Last active
September 3, 2023 03:01
-
-
Save hidao80/0a67c47377260322d97bc43a20529156 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(function(){function t(t){const n=t.split(s);let e="";for(let t of n)t=t.trim(),t==n.length-1&&0==t.length||(e+="> "+t+s);return e}function n(){const n=window.getSelection();return n&&""!=n?t(o(n+s).trim()):""}function e(){const t=n(),e=document.title,o=document.URL,i=window.getSelection(),r=i?`[${c}](${o}#:~:text=${encodeURIComponent(i)})`:"";return t+s+r+s+"『"+e.trim()+"』"+s+o+s}function o(t){return t.replace(new RegExp(u,"g"),"")}const i="https://misskey.dev",c="選択範囲へ直リンク",r="\n",u="\r",s=r,d="width=600,height=400",l=encodeURIComponent(e()),m=`${i}/share?text=${l}`;window.open(m,"Notes",d)})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Copyright (c) 2022 hidao80 | |
* Released under the MIT license | |
* https://opensource.org/licenses/mit-license.php | |
*/ | |
(function () { | |
const instance = "https://misskey.dev"; | |
const link_text = "選択範囲へ直リンク"; | |
const LF = '\n'; | |
const CR = '\r'; | |
const BR = LF; | |
const CSS_SIZE_POPWINDOW = 'width=600,height=400'; | |
function addHeaderQuote(str) { | |
const lines = str.split(BR); | |
let result = ''; | |
for (let line of lines) { | |
line = line.trim(); | |
if (!(line == lines.length - 1 && line.length == 0)) { | |
result += '> ' + line + BR; | |
} | |
} | |
return result; | |
} | |
function getSelectedStringAsQuote() { | |
const str = window.getSelection(); | |
return (!str || str == '') ? '' : addHeaderQuote(uniformBRtoLF(str + BR).trim()); | |
} | |
function makeComment() { | |
const str = getSelectedStringAsQuote(); | |
const title = document.title; | |
const url = document.URL; | |
const selection = window.getSelection(); | |
const link = selection ? `[${link_text}](${url}#:~:text=${encodeURIComponent(selection)})` : ''; | |
return str + BR + link + BR + '『' + title.trim() + '』' + BR + url + BR; | |
} | |
function uniformBRtoLF(str) { | |
return str.replace(new RegExp(CR, 'g'), '') | |
} | |
const str = encodeURIComponent(makeComment()); | |
const title = `${instance}/share?text=${str}`; | |
window.open(title, 'Notes', CSS_SIZE_POPWINDOW) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment