首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Tampermonkey 编写一个首页跳转的脚本

Tampermonkey 编写一个首页跳转的脚本

原创
作者头像
陶陶name
发布2022-05-12 08:55:28
发布2022-05-12 08:55:28
7280
举报
文章被收录于专栏:陶陶计算机陶陶计算机

每次打开浏览器时,总是会跳到一个其他的网页上,关也关不掉,很烦,写一个脚本直接跳转

代码语言:txt
复制
// ==UserScript==
// @name         页面跳转
// @version      1.0.1
// @author       name
// @namespace    https://greasyfork.org/zh-CN/users/378268
// @include      *

//               ↓ jQuery核心文件 ↓
// @require      https://greasyfork.org/scripts/39025-micoua-jquery-min-js/code/Micoua_jQuery_min_js.js?version=255336
//               ↓ jQueryUI核心文件 ↓
// @require      https://greasyfork.org/scripts/40306-micoua-jqueryui-min-js/code/Micoua_jQueryUI_min_js.js?version=267377

// @grant        unsafeWindow
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_deleteValue
// @grant        GM_listValues
// ==/UserScript==

(function () {
    /**
     * 主入口
     */
    function main() {
        gotoWeb(); // 跳转网页
    }

    /**
     * 全局变量
     */
    var currentURL = window.location.href; // 获取当前网页地址
    var url = "https://www.google.com.hk/?hl=zh-cn"; // 预定义跳转网页

    /**
     * 跳转网页
     */
    gotoWeb = function () {
        /** 定义拦截网页 */
        var urls = {
            "googleHelpURLs": [
                "123.hao245.com",
                "360.hao245.com",
                "hao123.com/?tn="
            ]
        };
        /** 拦截网站并跳转 */
        var googleHelpURLs = GM_getValue("googleHelpURLs") === undefined ? urls.googleHelpURLs : $.merge(GM_getValue("googleHelpURLs"), urls.googleHelpURLs);
        for (var i = 0; i < googleHelpURLs.length; i++) { if (currentURL.indexOf(googleHelpURLs[i]) != -1) { window.location.href = url; return; } }
    };

    /**
     * 加载完所有数据后进入主函数
     */
    if (true) main();
})();

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档