Skip to content

Instantly share code, notes, and snippets.

@kn1cht
Last active June 23, 2019 00:41
Show Gist options
  • Select an option

  • Save kn1cht/911ca1e4c3e92c636a603dce940eae99 to your computer and use it in GitHub Desktop.

Select an option

Save kn1cht/911ca1e4c3e92c636a603dce940eae99 to your computer and use it in GitHub Desktop.

Revisions

  1. kn1cht revised this gist Jun 23, 2019. 1 changed file with 8 additions and 7 deletions.
    15 changes: 8 additions & 7 deletions script.js
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,19 @@
    scrapbox.PopupMenu.addButton({
    title : 'Embed Tweet',
    onClick : text => {
    const convertContent = content => {
    const convertContent = (content, indent) => {
    const replaced = content
    .replace(/<a href="(https?:.*?)">(.*?)<\/a>/g, '[$1 $2]')
    .replace(/<br>/g, '\n>');
    .replace(/<br>/g, `\n${indent}`);
    const elem = document.createElement('div');
    elem.innerHTML = replaced;
    return elem.innerText;
    return indent + elem.innerText;
    }
    const tweetRegex = /<blockquote[\w"\-= ]*><p[\w"\-= ]*>(?<content>.*)<\/p>&mdash;(?<author>.*)(?<link><a.*>)<\/blockquote>\n<script.*?><\/script>/;
    const tweetRegex = /(?<spaces>[\t ]*)<blockquote[\w"\-= ]*><p[\w"\-= ]*>(?<content>.*)<\/p>&mdash;(?<author>.*)(?<link><a.*>)<\/blockquote>[\n\t ]*<script.*?><\/script>/;
    const match = text.match(tweetRegex);
    if(!match) return;
    const {content, author, link} = match.groups;
    return text.replace(tweetRegex, `>${convertContent(content)}\n>\t—${author} ${convertContent(link)}`);
    const {spaces, content, author, link} = match.groups;
    const ind = `${spaces}>`;
    return text.replace(tweetRegex, convertContent(content, ind) + '\n' + convertContent(`\t—${author} ${link}`, ind));
    }
    })
    })
  2. kn1cht revised this gist May 2, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion script.js
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ scrapbox.PopupMenu.addButton({
    elem.innerHTML = replaced;
    return elem.innerText;
    }
    const tweetRegex = /<blockquote[\w"\-= ]*><p[\w"\-= ]*>(?<content>.*)<\/p>&mdash;(?<author>.*)(?<link><a.*>)<\/blockquote>/;
    const tweetRegex = /<blockquote[\w"\-= ]*><p[\w"\-= ]*>(?<content>.*)<\/p>&mdash;(?<author>.*)(?<link><a.*>)<\/blockquote>\n<script.*?><\/script>/;
    const match = text.match(tweetRegex);
    if(!match) return;
    const {content, author, link} = match.groups;
  3. kn1cht revised this gist Apr 30, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions script.js
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ scrapbox.PopupMenu.addButton({
    onClick : text => {
    const convertContent = content => {
    const replaced = content
    .replace(/<a.*href="(https?:.*)">(.*)<\/a>/, '[$1 $2]')
    .replace(/<a href="(https?:.*?)">(.*?)<\/a>/g, '[$1 $2]')
    .replace(/<br>/g, '\n>');
    const elem = document.createElement('div');
    elem.innerHTML = replaced;
    @@ -15,4 +15,4 @@ scrapbox.PopupMenu.addButton({
    const {content, author, link} = match.groups;
    return text.replace(tweetRegex, `>${convertContent(content)}\n>\t—${author} ${convertContent(link)}`);
    }
    })
    })
  4. kn1cht created this gist Apr 30, 2019.
    18 changes: 18 additions & 0 deletions script.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    scrapbox.PopupMenu.addButton({
    title : 'Embed Tweet',
    onClick : text => {
    const convertContent = content => {
    const replaced = content
    .replace(/<a.*href="(https?:.*)">(.*)<\/a>/, '[$1 $2]')
    .replace(/<br>/g, '\n>');
    const elem = document.createElement('div');
    elem.innerHTML = replaced;
    return elem.innerText;
    }
    const tweetRegex = /<blockquote[\w"\-= ]*><p[\w"\-= ]*>(?<content>.*)<\/p>&mdash;(?<author>.*)(?<link><a.*>)<\/blockquote>/;
    const match = text.match(tweetRegex);
    if(!match) return;
    const {content, author, link} = match.groups;
    return text.replace(tweetRegex, `>${convertContent(content)}\n>\t—${author} ${convertContent(link)}`);
    }
    })