scrapbox-mousetrap-installer
/icons/hr.icon
code:script.js
export function installMousetrap({
useBindDictionary = false,
useGlobalBind = false,
usePause = false,
useRecord = false} = {}) {
installCDN({id: 'mousetrap-for-scrapbox',
url: '//cdnjs.cloudflare.com/ajax/libs/mousetrap/1.6.5/mousetrap.min.js'});
if (useGlobalBind) {
installCDN({id: 'mousetrap-bind-dictionary-for-scrapbox',
url: '//cdnjs.cloudflare.com/ajax/libs/mousetrap/1.6.5/plugins/bind-dictionary/mousetrap-bind-dictionary.min.js'});
}
if (useGlobalBind) {
installCDN({id: 'mousetrap-global-bind-for-scrapbox',
url: '//cdnjs.cloudflare.com/ajax/libs/mousetrap/1.6.5/plugins/global-bind/mousetrap-global-bind.min.js'});
}
if (usePause) {
installCDN({id: 'mousetrap-pause-for-scrapbox',
url: '//cdnjs.cloudflare.com/ajax/libs/mousetrap/1.6.5/plugins/pause/mousetrap-pause.min.js'});
}
if (useRecord) {
installCDN({id: 'mousetrap-record-for-scrapbox',
url: '//cdnjs.cloudflare.com/ajax/libs/mousetrap/1.6.5/plugins/record/mousetrap-record.min.js'});
}
}
function installCDN({id,url}) {
const oldScript = document.getElementById(id);
oldScript?.parentNode.removeChild(oldScript);
const script = document.createElement("script");
script.src = url;
script.id = id;
document.body.appendChild(script);
}