Pixiv Direct External Link

When clicking links in the description redirect directly to the url.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Pixiv Direct External Link
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  When clicking links in the description redirect directly to the url.
// @author       MatteCrystal
// @match        *://www.pixiv.net/*
// @icon         https://www.google.com/s2/favicons?domain=pixiv.net
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @run-at       document-idle
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function redirectLink(){
        console.log("Pixiv Direct External Link Script Started");
        console.log("figcaption length: " + document.querySelector("figcaption").innerHTML.length);

        let linksLength = document.querySelectorAll('figcaption a[href^="/jump"]').length;

        console.log("Length: " + document.querySelectorAll('figcaption a[href^="/jump"]').length);
        for(let i = 0; i < linksLength; i++){
            console.log("i:" + i);
            console.log("href = " + document.querySelectorAll('figcaption a[href^="/jump"]')[0].href);
            document.querySelectorAll('figcaption a[href^="/jump"]')[0].href = document.querySelectorAll('figcaption a[href^="/jump"]')[0].text;
        }
    }
    
    waitForElementToDisplay("figcaption",function(){
        redirectLink();
    },1000,9000);

    function waitForElementToDisplay(selector, callback, checkFrequencyInMs, timeoutInMs) {
        var startTimeInMs = Date.now();
        (function loopSearch() {
            if (document.querySelector(selector) != null && document.querySelector(selector).innerHTML.length != undefined ) {
                console.log("html length: " + document.querySelector(selector).innerHTML.length);
                callback();
                return;
            }
            else {
                setTimeout(function () {
                    if (timeoutInMs && Date.now() - startTimeInMs > timeoutInMs)
                        return;
                    loopSearch();
                }, checkFrequencyInMs);
            }
        })();
    }
})();