首页 > 其他分享 >宣传脚本 NoFishing

宣传脚本 NoFishing

时间:2024-08-19 10:09:33浏览次数:4  
标签:NoFishing 脚本 style appendChild 宣传 let createElement document panel

这个脚本费事作者一周,作者不断思考 \(\texttt{UI}\) 设计和用户体验,最后写成这样。如果有想做贡献的小朋友也可以在 link 中提建议、改代码,谢谢。

// ==UserScript==
// @name         NoFishing
// @namespace    http://tampermonkey.net/
// @version      2.5
// @description  禁止颓废。
// @author       Kimi
// @match        *://*/*
// @grant        GM_setValue
// @grant        GM_getValue
// @updateURL    https://github.com/zjx-kimi/NoFishing/raw/master/NoFishing.meta.js
// @downloadURL  https://github.com/zjx-kimi/NoFishing/raw/master/NoFishing.js
// ==/UserScript==

(function() {
    'use strict';

    // 白名单
    let whitelist = GM_getValue("whitelist", []);

    // 当前访问的网站
    const currentSite = window.location.hostname;

    // 增加访问次数
    function increaseVisitCount() {
        let visitCount = GM_getValue("visitCount", 0);
        visitCount += 1;
        GM_setValue("visitCount", visitCount);
        return visitCount;
    }

    // 检查当前网站是否在白名单中
    function isWhitelisted(site) {
        return whitelist.includes(site);
    }

    // 显示气泡提示
    // 显示气泡提示
    function showToast(message, duration = 3000) {
        let toast = document.createElement('div');
        toast.style.position = 'fixed';
        toast.style.bottom = '20px';
        toast.style.left = '50%';
        toast.style.transform = 'translateX(-50%)';
        toast.style.backgroundColor = 'rgba(0, 0, 0, 0.8)';
        toast.style.color = 'white';
        toast.style.padding = '10px 20px';
        toast.style.borderRadius = '4px';
        toast.style.zIndex = 10001;
        toast.style.fontSize = '16px';
        toast.style.boxShadow = '0 2px 10px rgba(0, 0, 0, 0.3)';
        toast.style.whiteSpace = 'pre-wrap'; // 保持换行符
        toast.style.textAlign = 'center'; // 中央对齐
        toast.style.maxWidth = '300px'; // 限制宽度
        toast.style.wordWrap = 'break-word'; // 自动换行

        // 使用 HTML 内容来支持换行
        toast.innerHTML = message;

        document.body.appendChild(toast);

        setTimeout(() => {
            toast.style.transition = 'opacity 0.5s';
            toast.style.opacity = '0';
            setTimeout(() => {
                document.body.removeChild(toast);
            }, 500);
        }, duration);
    }



    // 显示自定义确认弹窗
    function showConfirmationDialog(message, onConfirm) {
        let overlay = document.createElement('div');
        overlay.style.position = 'fixed';
        overlay.style.top = 0;
        overlay.style.left = 0;
        overlay.style.width = '100%';
        overlay.style.height = '100%';
        overlay.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
        overlay.style.zIndex = 10002;
        overlay.style.display = 'flex';
        overlay.style.alignItems = 'center';
        overlay.style.justifyContent = 'center';

        let dialog = document.createElement('div');
        dialog.style.backgroundColor = 'white';
        dialog.style.borderRadius = '8px';
        dialog.style.padding = '20px';
        dialog.style.boxShadow = '0 4px 12px rgba(0, 0, 0, 0.3)';
        dialog.style.maxWidth = '400px';
        dialog.style.width = '100%';
        dialog.style.textAlign = 'center';

        let text = document.createElement('p');
        text.textContent = message;
        text.style.marginBottom = '20px';

        let confirmButton = document.createElement('button');
        confirmButton.textContent = '确认';
        confirmButton.style.padding = '10px 20px';
        confirmButton.style.backgroundColor = '#007bff';
        confirmButton.style.color = 'white';
        confirmButton.style.border = 'none';
        confirmButton.style.borderRadius = '4px';
        confirmButton.style.cursor = 'pointer';
        confirmButton.onclick = () => {
            document.body.removeChild(overlay);
            onConfirm();
        };

        let cancelButton = document.createElement('button');
        cancelButton.textContent = '取消';
        cancelButton.style.padding = '10px 20px';
        cancelButton.style.backgroundColor = '#6c757d';
        cancelButton.style.color = 'white';
        cancelButton.style.border = 'none';
        cancelButton.style.borderRadius = '4px';
        cancelButton.style.cursor = 'pointer';
        cancelButton.style.marginLeft = '10px';
        cancelButton.onclick = () => {
            document.body.removeChild(overlay);
        };

        dialog.appendChild(text);
        dialog.appendChild(confirmButton);
        dialog.appendChild(cancelButton);
        overlay.appendChild(dialog);
        document.body.appendChild(overlay);
    }

    // 显示控制面板按钮
    function showControlPanelButton() {
        let panel = document.createElement('div');
        panel.style.position = 'fixed';
        panel.style.bottom = '10px';
        panel.style.right = '10px';
        panel.style.backgroundColor = '#f9f9f9';
        panel.style.border = '1px solid #ccc';
        panel.style.borderRadius = '4px';
        panel.style.padding = '5px';
        panel.style.zIndex = 10000;
        panel.style.cursor = 'pointer';
        panel.style.display = 'grid';
        panel.style.gridTemplateColumns = '1fr 1fr'; // 2x2 布局

        const iconSize = '18px'; // 调整后的图标大小

        // ⚙ 控制面板按钮
        let controlButton = document.createElement('span');
        controlButton.textContent = '⚙';
        controlButton.style.cursor = 'pointer';
        controlButton.title = '打开控制面板';
        controlButton.style.textAlign = 'center';
        controlButton.style.padding = '5px';  // 缩小内边距
        controlButton.style.backgroundColor = '#007bff';
        controlButton.style.color = 'white';
        controlButton.style.borderRadius = '4px';
        controlButton.style.border = '2px solid #007bff'; // 缩小边框
        controlButton.style.display = 'flex';
        controlButton.style.alignItems = 'center';
        controlButton.style.justifyContent = 'center';
        controlButton.style.fontSize = iconSize;
        controlButton.onclick = function() {
            openControlPanel();
        };

        // ➕ 添加到白名单按钮
        let addButton = document.createElement('span');
        addButton.textContent = '➕';
        addButton.style.cursor = 'pointer';
        addButton.title = '将当前网站加入白名单';
        addButton.style.textAlign = 'center';
        addButton.style.padding = '5px';  // 缩小内边距
        addButton.style.backgroundColor = '#28a745';
        addButton.style.color = 'white';
        addButton.style.borderRadius = '4px';
        addButton.style.border = '2px solid #28a745'; // 缩小边框
        addButton.style.display = 'flex';
        addButton.style.alignItems = 'center';
        addButton.style.justifyContent = 'center';
        addButton.style.fontSize = iconSize;
        addButton.onclick = function() {
            if (!isWhitelisted(currentSite)) {
                whitelist.push(currentSite);
                GM_setValue("whitelist", whitelist);
                showToast("已加入白名单: " + currentSite);
            } else {
                showToast("该网站已在白名单中。");
            }
        };

        // ❌ 删除当前网站按钮
        let deleteButton = document.createElement('span');
        deleteButton.textContent = '❌';
        deleteButton.style.cursor = 'pointer';
        deleteButton.title = '删除当前网站';
        deleteButton.style.textAlign = 'center';
        deleteButton.style.padding = '5px';  // 缩小内边距
        deleteButton.style.backgroundColor = '#ffffff';
        deleteButton.style.color = '#dc3545';
        deleteButton.style.borderRadius = '4px';
        deleteButton.style.border = '2px solid #dc3545'; // 缩小边框
        deleteButton.style.display = 'flex';
        deleteButton.style.alignItems = 'center';
        deleteButton.style.justifyContent = 'center';
        deleteButton.style.fontSize = iconSize;
        deleteButton.onclick = function() {
            if (isWhitelisted(currentSite)) {
                whitelist = whitelist.filter(site => site !== currentSite);
                GM_setValue("whitelist", whitelist);
                showToast("已删除: " + currentSite);
                window.location.href = 'https://codeforces.com/problemset/status?friends=on';
            } else {
                showToast("该网站不在白名单中。");
            }
        };

        // 

标签:NoFishing,脚本,style,appendChild,宣传,let,createElement,document,panel
From: https://www.cnblogs.com/kimi0705/p/18366759/NoFishing

相关文章

  • Elsa V3学习之脚本
    在前面的文章中,可以看到我们经常使用JS脚本来获取变量的值。在Elsa中是支持多种脚本的,最常用的基本是JS脚本和C#脚本。本文来介绍以下这两个脚本使用。Javascript在ELSA中的javascript是通过Jint这个包来实现的。通过JS映射到C#内部的方法中。可以在代码中先预定义我们的Functi......
  • Bat To Exe Converter:一键转换,让批处理脚本秒变执行神器!
    前言在数字化时代,批处理脚本(BAT文件)作为自动化任务处理的得力助手,广泛应用于系统管理和软件开发中;然而,BAT文件在执行时通常需要依赖命令行界面,这在非技术用户或非特定环境下可能会造成一定的使用障碍;为此,一款能够将BAT文件高效转换为可执行文件(EXE文件)的工具显得尤为重要;BatT......
  • bash shell脚本接受多个参数
    !/bin/bashDefaultvaluesforalloptionsud_default="default_ud_value"a_default="default_a_value"b_default="default_b_value"c_default="default_c_value"d_default="default_d_value"e_default="defau......
  • jenkins配置脚本
    pipeline{agentanytools{maven'Maven3.9.2'}stages{stage('拉取代码'){steps{gitbranch:'main',credentialsId:'chatx',url:'git路径'......
  • jenkins pipline脚本 获取git分支
    必须先禁用脚本安全性,参考文章:https://www.cnblogs.com/xiao987334176/p/18365397 点击ManageJenkins-->ScriptConsole输入以下脚本://定义Git命令defcmd="gitls-remote--headshttps://oauth2:[email protected]/xx.git"//执行命令并获取输出defproc=c......
  • shell_获取当前最新的sh脚本并执行 shell脚本 配合curl使用
    获取最新的shell脚本并执行#!/bin/bash#获取当前目录current_dir=$(pwd)#获取当前脚本的绝对路径script_path=$(readlink-f"$0")#使用find查找以temp开头且以.sh结尾的文件,并按修改时间排序latest_file=$(find"$current_dir"-maxdepth1-name"*.sh"-print0|......
  • XSS-跨站脚本攻击
    目录XSS简介XSS分类反射型XSS(非持久型XSS)存储型XSS(持久型XSS)DOM型XSSHTML文档解析过程例题HTML解析字符实体(characterentities)HTML字符实体(HTMLcharacterentities)字符引用(characterreferences)URL解析JavaScript解析解析流XSS练习DomClobberingDOM型......
  • yum源仓库更换脚本
    一、需求:一键式脚本更换国内的阿里源二、脚本#!/bin/bash#数据迁移备份yum_bak='mv/etc/yum.repos.d/CentOS-Base.repo/etc/yum.repos.d/CentOS-Base.repo.backup'#查看当前仓库yum_repo="yumrepolist|grep'*'|awk-F"[:.]"'NR==1{print$3}'......
  • Linux c程序中获取shell脚本输出(如获取system命令输出)
    在工作中遇到一个小问题,就是想获取函数system()执行之后打印的字符串信息。这个功能还是很实用的,能为我们节省很多开发时间,特地整理了一下相关知识点分享给大家。1.使用临时文件1.1使用shell的重定向首先想到的方法就是将命令输出重定向到一个临时文件,在我们的应用程序中读......
  • 1、.Net UI框架:MAUI - .Net宣传系列文章
    .NETMAUI(Multi-platformAppUI)是一个跨平台的UI框架,它是.NET统一应用模型的一部分,允许开发者使用C#和.NET来创建适用于iOS、Android、macOS和Windows的应用程序。MAUI继承了Xamarin.Forms的一些概念,但提供了更多的原生平台集成和改进的性能。MAUI的关键特性包括:......