Skip to content

Instantly share code, notes, and snippets.

@SnO2WMaN
Last active December 16, 2022 01:08
Show Gist options
  • Save SnO2WMaN/21ac444ef4936029f4d27797b3af2457 to your computer and use it in GitHub Desktop.
Save SnO2WMaN/21ac444ef4936029f4d27797b3af2457 to your computer and use it in GitHub Desktop.
(function () {
const soundcloudRegex = /https:\/\/soundcloud.com\/.+\/.+/;
const nicovideoRegex = /https:\/\/www.nicovideo.jp\/watch\/([a-z]{2}\d+)+/;
let pageTitle = document.title;
let lines = ["", `[${window.location.href} ${document.title}]`];
if (soundcloudRegex.test(window.location.href)) {
pageTitle = document.title.slice(
"Stream ".length,
-" | Listen online for free on SoundCloud".length
);
lines = [
`[https://soundcloud2image.vercel.app/image?url=${window.location.href}#.png ${window.location.href}]`,
];
} else if (nicovideoRegex.test(window.location.href)) {
pageTitle = document.title.slice(0, -"- ニコニコ動画".length);
const m = window.location.href.match(nicovideoRegex);
lines = [
`[https://nicothumb2img.vercel.app/image/${m[1]}#.png https://nico.ms/${m[1]}]`,
];
}
var title = window.prompt(
`Scrap "${pageTitle}" to Internet Explorer 2.0.`,
pageTitle
);
if (!title) return;
var quote = window.getSelection().toString();
if (quote.trim())
lines = lines.concat(
quote.split(/\n/g).map(function (line) {
return ` > ${line}`;
})
);
lines.push("");
window.open(
`https://scrapbox.io/sno2wman/${encodeURIComponent(
title.trim()
)}?body=${encodeURIComponent(lines.join("\n"))}`
);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment