Free Read And Go

链接直接跳转,阅读全文(todo)

当前为 2023-01-14 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Free Read And Go
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  链接直接跳转,阅读全文(todo)
// @author       Leon406
// @match        *://**/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=greasyfork.org
// @grant        none
// @license      GPL-3.0 License
// ==/UserScript==

const host = window.location.host

    const REAL_GO = {
    "gitee.com": {
        prefix: "https://gitee.com/link?target=",
        query: "target",
        action: urlDecode
    },
     "sspai.com": {
        prefix: "https://sspai.com/link?",
        query: "target",
        action: urlDecode
    },
    "www.youtube.com": {
        prefix: "https://www.youtube.com/redirect?",
        query: "q",
        action: urlDecode
    },
    "mail.qq.com": {
        fuc: () => get_elements("#contentDiv a").forEach(stopropagation)
    },
    "tieba.baidu.com": {
        fuc: () => get_elements("#container a").forEach(stopropagation)
    },
}

function findRule() {

    for (key in REAL_GO) {}
}

function find_all_iframe(doc = document) {
    let frame = doc.querySelectorAll("iframe");
    if (frame.length === 0)
        return [];
    let frames = Array.from(frame)
        .filter(el => el.contentDocument)
        if (frames.length > 0) {
            let frames2 = frames.flatMap(el => find_all_iframe(el.contentDocument))
                if (frames2.length > 0) {
                    frames2.forEach(e => frames.push(e))
                }
        }
        return frames;
}

function get_elements(selector, cond = el => el) {
    let elements = Array.from(document.querySelectorAll(selector)).filter(cond);
    if (elements.length === 0) {
        elements = find_all_iframe()
            .flatMap(el => Array.from(el.contentDocument.querySelectorAll(selector)))
            .filter(el => cond(el));
    }
    return elements;
}

const stopEvent = (e) => {
    console.log("eeee", e)
    // 阻止事件冒泡, 因为上层元素绑定的click事件会重定向
    if (e.stopPropagation) {
        e.stopPropagation();
    }
};

function stopropagation(aTag) {
    if (aTag.onclick && aTag.onclick != stopEvent)
        aTag.onclick = stopEvent
}

function interval(fuc, timeout = 500) {
    setInterval(fuc, timeout)
}

function urlDecode(aTag, query) {
    console.log("urlDecode", query, aTag)
    aTag.href = decodeURIComponent(new URL(aTag.href).searchParams.get(query))
}

// 查询所有a标签
function findAllHref(rule = "http") {
    return get_elements("a", el => el.href.includes(rule))
}

(function () {
    'use strict';
    window.onload = function () {
        let rule = REAL_GO[host];
        setTimeout(() => {
            console.log("rule", rule)
            if (rule) {
                findAllHref(rule.prefix).forEach(el => {
                    rule.action && rule.action(el, rule.query)
                    rule.fuc && interval(rule.fuc)
                });
            }

        }, 3000)
    }
})();