他のページに転送するUserScript
出典
Scrapboxで、 goto: と書くと他のページに転送してくれるUserScriptを作った!
表記ゆれとか英語表記とかに対応できて便利。
https://github.com/cosnomi/scrapbox-scripts/blob/master/redirect.js
https://gyazo.com/e12a13a0c4d5f5bfc4a6c2c147740061
https://twitter.com/cosnomi/status/1233777162525671424?s=19
code:script.js
function applyRedirectIfNeeded() {
// Clicking a.page-link virtually is faster than updating location.href
// as Scrapbox uses react-router (maybe)
if (scrapbox.Page.lines1.nodes0 === 'goto:') {
$('a.page-link')
.get(0)
.click()
}
}
let sectionTitle = $('title').get(0)
var observer = new MutationObserver(() => {
applyRedirectIfNeeded()
})
observer.observe(sectionTitle, { childList: true })
// needs to be called manually here
// because observer is not triggerd for the initial page
applyRedirectIfNeeded()
console.log('redirect module loaded')
#UserScript UserScript.icon