Last active
July 22, 2023 00:07
-
-
Save XCanG/dddf2b913312d797331a92a18a9d2400 to your computer and use it in GitHub Desktop.
Use browser addon like Tampermonkey https://www.tampermonkey.net/ to add custom JavaScript in your browser. To install click on Raw button.
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
// ==UserScript== | |
// @name Fix Fanbox external links | |
// @namespace https://www.fanbox.cc/ | |
// @version 1.0 | |
// @description This script fix Mega links at the moment | |
// @author X4 | |
// @match https://*.fanbox.cc/posts/* | |
// @match https://*.fanbox.cc/@*/posts/* | |
// @icon https://icons.duckduckgo.com/ip2/fanbox.cc.ico | |
// @grant none | |
// ==/UserScript== | |
(async () => { | |
"use strict"; | |
const wait_for_el = (selector) => { | |
return new Promise(resolve => { | |
if (document.querySelector(selector)) { | |
return resolve(document.querySelector(selector)); | |
} | |
const observer = new MutationObserver(mutations => { | |
if (document.querySelector(selector)) { | |
resolve(document.querySelector(selector)); | |
observer.disconnect(); | |
} | |
}); | |
observer.observe(document.body, { | |
childList: true, | |
subtree: true | |
}); | |
}); | |
} | |
const p = await wait_for_el(".public-DraftEditor-content > div"); | |
for (const s of p.querySelectorAll("span[data-text]")) { | |
if (!/\b(?<!\/)[\w\-_]{8}#[\w\-_]{22}\b/.test(s.innerHTML)) continue; | |
s.innerHTML = s?.innerHTML?.replace?.( | |
/\b(?<!\/)[\w\-_]{8}#[\w\-_]{22}\b/g, | |
`<a href="https://mega.nz/folder/$&">https://mega.nz/folder/$&</a>` | |
); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment