使用方法:新增一個書籤,把底下 javascript: ...
的程式貼到書籤的網址內,然後去你想要用的網頁,點一下書籤就會載入這些 JS 進來,你可以自己修改想要載入的 JS 清單。
javascript: (async () => { const loadScript = async url => new Promise((resolve, reject) => { const script = document.createElement('script'); script.src = url; script.onload = () => resolve(); script.onerror = () => reject(new Error(`Failed to load script: ${url}`)); document.head.appendChild(script); }); console.log(`js-snippets.js started`); const LIBRARIES_URL = 'https://gist.githubusercontent.com/taichunmin/5171d5c7de23d8270c1f03be75593713/raw/libraries.json'; const libraries = await (await fetch(`${LIBRARIES_URL}?t=${Date.now()}`)).json(); await Promise.all(libraries.map(loadScript)); const dayjsPlugins = _.chain(_.keys(window)).filter(k => _.startsWith(k, 'dayjs_plugin_')).value(); console.log(`found ${dayjsPlugins.length} plugins of dayjs`); for (const plugin of dayjsPlugins) window.dayjs.extend(window[plugin]); })()
// javascript:
(async () => {
const loadScript = async url => new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = url;
script.onload = () => resolve();
script.onerror = () => reject(new Error(`Failed to load script: ${url}`));
document.head.appendChild(script);
});
console.log(`js-snippets.js started`);
const LIBRARIES_URL = 'https://gist.githubusercontent.com/taichunmin/5171d5c7de23d8270c1f03be75593713/raw/libraries.json';
const libraries = await (await fetch(`${LIBRARIES_URL}?t=${Date.now()}`)).json();
await Promise.all(libraries.map(loadScript));
const dayjsPlugins = _.chain(_.keys(window))
.filter(k => _.startsWith(k, 'dayjs_plugin_'))
.value();
console.log(`found ${dayjsPlugins.length} plugins of dayjs`);
for (const plugin of dayjsPlugins) window.dayjs.extend(window[plugin]);
})()