Plurk no redirector

try to take over the world!

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Plurk no redirector
// @namespace    http://mmis1000.me/
// @version      0.1.10
// @description  try to take over the world!
// @author       You
// @match        https://www.plurk.com/*
// @grant        none
// ==/UserScript==

/* global jQuery, getBody, Media */
jQuery(function() {
    // window.Media = null;

    function shouldBeExclude(el) {
        function checkStop(el) {
            return jQuery(el).is('a.ex_link') &&
                !jQuery(el).is('.pictureservices') &&
                !jQuery(el).is('.iframeembed') &&
                !jQuery(el).is('.plink') &&
                !(/^https?:\/\/[^\.]+\.plurk\.com\//).test(el.attr('href') + '');
        }

        let currentEl = jQuery(el);
        let shouldStop = checkStop(currentEl)

        while (currentEl.get(0) && !shouldStop) {
            currentEl = currentEl.parent();
            shouldStop = shouldStop || checkStop(currentEl);
        }

        console.log('check', shouldStop, shouldStop ? currentEl : el);

        if (shouldStop) {
            currentEl.attr('rel', 'noreferrer noopener')
        }

        return shouldStop;
    }

    var $body = jQuery('#layout_body');
    $body.on('click', '#layout_content a.ex_link', function(el){el.target && el.target.setAttribute('rel', 'noreferrer noopener')})

    jQuery._data(jQuery('#layout_body').get(0), 'events').click
        .map((o)=>[o.handler.toString(), o])
        // .filter((arr)=>(/hasClass\("ex_link"\)/).test(arr[0]) || (/_hideLink/).test(arr[0]))
        .forEach(function ([code, layoutBodyClickData]) {
        jQuery('#layout_body').off('click', layoutBodyClickData.handler);
        const handler = function (ev) {
            if (shouldBeExclude(ev.target)) {
                console.log('stop go plurk')
                return;
            } else {
                return layoutBodyClickData.handler.call(this, ev);
            }
        }

        if (layoutBodyClickData.selector) {
            jQuery('#layout_body').on('click', layoutBodyClickData.selector, handler)
        } else {
            jQuery('#layout_body').on('click', handler)
        }
    })

    try {
        const verticalTimelineClickData = jQuery._data(jQuery('#vert_timeline').get(0), 'events').click
        .map((o)=>[o.handler.toString(), o])
        .filter((arr)=>(/window\.open\(this\.href\)/).test(arr[0]))[0][1]

        jQuery('#vert_timeline').off('click', verticalTimelineClickData.handler)

        jQuery._data(jQuery('#vert_timeline').get(0), 'events').click
            .map((o)=>[o.handler.toString(), o])
            // .filter((arr)=>(/_hideLink/).test(arr[0]))
            .forEach(function ([code, layoutBodyClickData]) {
            jQuery('#vert_timeline').off('click', layoutBodyClickData.handler);
            const handler = function (ev) {
                if (shouldBeExclude(ev.target)) {
                    console.log('stop go plurk', ev.target)
                    return;
                } else {
                    return layoutBodyClickData.handler.call(this, ev);
                }
            }

            if (layoutBodyClickData.selector) {
                jQuery('#vert_timeline').on('click', layoutBodyClickData.selector, handler)
            } else {
                jQuery('#vert_timeline').on('click', handler)
            }
        })
    } catch (e) {
        // '#vert_timeline' does not exist
    }
    console.log('loaded')
});