Tampermonkey Clean tmclean

Delete all disabled and duplicated scripts.

目前为 2022-01-27 提交的版本。查看 最新版本

// ==UserScript==
// @name         Tampermonkey Clean tmclean
// @namespace    https://userscript.snomiao.com/
// @version      0.0.1
// @description  Delete all disabled and duplicated scripts.
// @author       [email protected]
// @match        *://calendar.google.com/*
// @grant        none
// ==/UserScript==

// chrome-extension://dhdgffkkebhmkfjojejmpbldmpobfkfo/options.html#url=aHR0cHM6Ly93d3cuemhpaHUuY29tL2NyZWF0b3I=&nav=dashboard

// delete all disabled scripts
[...document.querySelectorAll('[title="Delete"]')]
    .filter((e) =>
        e.parentElement.parentElement.parentElement.innerHTML.match(
            /title="Disabled"/
        )
    )
    .map((e) => e.click());

// delete duplicated scripts (keep the first)
[...document.querySelectorAll('tr.scripttr')]
    .map((e) => ({
        id: e.querySelector('.script_name')?.textContent,
        e,
    }))
    .filter(({ id }) => id)
    .reduce(
        (dups, { id, e }, i, a) => [
            ...dups,
            a.slice(0, i).find((e) => e.id === id),
        ],
        []
    )
    .filter((e) => e)
    .map(({ id, e }) => {
        console.log('Delete ' + id);
        e.querySelector('[title="Delete"]').click();
    });