您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Export and import NUS mods
当前为
// ==UserScript== // @name NUSMods Export Planner // @namespace http://tampermonkey.net/ // @version 2025-03-03 // @description Export and import NUS mods // @author Someone // @match https://nusmods.com/planner // @icon https://www.google.com/s2/favicons?sz=64&domain=nusmods.com // @run-at document-end // @grant none // @license MIT // ==/UserScript== (function() { 'use strict'; var plannerFunctions = window.plannerFunctions = {}; plannerFunctions.importPlanner = function () { if (confirm("Are you sure to overwrite the existing planner with new data?")) { var i0 = document.createElement('input'); var f0; i0.type = 'file'; i0.onchange = e => { f0 = e.target.files[0]; try { var reader = new FileReader(); reader.readAsText(f0,'UTF-8'); reader.onload = readerEvent => { var content = readerEvent.target.result; localStorage.setItem("persist:planner", content); window.location.reload(); } } catch (error) { console.error(error); alert(error); } } i0.click(); } } plannerFunctions.exportPlanner = function () { var plannerObj = localStorage.getItem("persist:planner"); function download(content, fileName, contentType) { var a = document.createElement("a"); var file = new Blob([content], {type: contentType}); a.href = URL.createObjectURL(file); a.download = fileName; a.click(); } download(plannerObj, 'planner.json', 'text/json'); } plannerFunctions.clearPlanner = function () { if (confirm("Are you ABSOLUTELY SURE that you want to remove all existing data from the planner?")) { localStorage.removeItem("persist:planner"); window.location.reload(); } } // https://stackoverflow.com/a/61511955 function waitForElm(selector) { return new Promise(resolve => { if (document.querySelector(selector)) { return resolve(document.querySelector(selector)); } const observer = new MutationObserver(mutations => { if (document.querySelector(selector)) { observer.disconnect(); resolve(document.querySelector(selector)); } }); // If you get "parameter 1 is not of type 'Node'" error, see https://stackoverflow.com/a/77855838/492336 observer.observe(document.body, { childList: true, subtree: true }); }); } window.addEventListener('load', async function () { let c = document.createElement("ul"); c.classList += 'R2Qt7mz2 list-unstyled'; c.innerHTML = '<li><button type="button" class="btn btn-block btn-outline-primary" onclick="plannerFunctions.exportPlanner();">Export Planner</button></li><li><button onclick="plannerFunctions.importPlanner();" class="btn btn-block btn-outline-primary">Import Planner</button></li><li> <button onclick="plannerFunctions.clearPlanner();" class="btn btn-block btn-outline-primary" type="button">Clear Planner</button></li>'; const h = await waitForElm('header'); h.after(c); }); })();