清空笔记助手

在页面左下角添加一个按钮,点击后清空笔记

当前为 2024-10-09 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         清空笔记助手
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  在页面左下角添加一个按钮,点击后清空笔记
// @author       你的名字
// @match        你的脚本运行的页面URL
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 检查是否已经加载了Font Awesome,如果没有,则添加
    if (!document.querySelector('link[href*="fontawesome.com"]')) {
        var link = document.createElement('link');
        link.rel = 'stylesheet';
        link.href = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css';
        document.head.appendChild(link);
    }

    // 创建按钮
    const button = document.createElement('button');
    button.innerHTML = '<i class="fas fa-trash-alt"></i> 清空笔记';
    button.style.position = 'fixed';
    button.style.bottom = '10px';
    button.style.left = '10px';
    button.style.zIndex = '9999';
    button.style.cursor = 'pointer';
    button.style.border = 'none';
    button.style.backgroundColor = 'transparent';
    button.style.padding = '10px';
    button.style.fontSize = '16px';
    button.style.color = 'red';
    button.title = '清空笔记';

    // 点击按钮执行操作
    button.onclick = function() {
        if (confirm('确定要清空笔记吗?')) {
            scrollAndCheck();
        }
    };

    // 将按钮添加到页面
    document.body.appendChild(button);

    // 你的原有脚本逻辑
    const scrollToBottom = (c) => {
        const element = document.querySelector(c);
        if (element) {
            element.scrollTop = element.scrollHeight;
        }
    };

    const isScrolledToBottom = () => {
        const element = document.querySelector('.end');
        return element ? element.getBoundingClientRect().bottom <= window.innerHeight : false;
    };

    function scrollAndCheck() {
        scrollToBottom('.memos');

        if (!isScrolledToBottom()) {
            console.log('No element with class "end" was found, continue scrolling...');
            setTimeout(scrollAndCheck, 1000); // 每秒检查一次
        } else {
            console.log('页面已下滑到最底部!');
            var elements = document.querySelectorAll('.item.danger');

            for (var i = 0; i < elements.length; i++) {
                if (elements[i].textContent.includes('删除')) {
                    elements[i].click();
                }
            }
        }
    }
})();