ao3 romantic relationship savior

hide works with romantic relationships on AO3

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        ao3 romantic relationship savior
// @description hide works with romantic relationships on AO3
// @namespace   https://greasyfork.org/en/scripts/464861
// @author       MM
// @match        https://archiveofourown.org/tags/*
// @match        https://archiveofourown.org/works?commit=Sort+and+Filter*
// @grant       none
// @version     1.1
// @license     none
// ==/UserScript==



/********************************/

(function($) {

    var works = $('li.blurb');
    if (!works[0]) return;

    var toggleClass = 'ao3-rels-hide-toggle',
        fold = $('<p>').addClass('fold').append(
            $('<span>').addClass(toggleClass).text('This work is hidden! '),
            $('<span>').addClass(toggleClass).html('This work was hidden. ').hide(),
            $('<span>').addClass('reason'),
            $('<span>').addClass('actions').append(
                $('<a>').addClass('action').css({
                    'position': 'absolute',
                    'right': 8,
                    'top': 10
                }).text('Unhide')
            )
        ),
        
        shouldBlacklist = function(work) {
            var relationships = work.find('.relationships').find('a.tag');
            //console.log(relationships);
            //var relationshiptags = [];
            let checkRomRel;
            let checkRel;
            let returnRomvalue;
            for(var i = 0; i< relationships.length; i++){
                checkRel = relationships[i].href;
                //relationshiptags.push(checkRel);
                if(checkRel !== null && checkRel !== undefined ) {
                    checkRomRel = checkRel.match(/\*s\*/g);
                    if(checkRomRel !== null && checkRomRel !== undefined) {
                        returnRomvalue = checkRomRel;
                    }
                }
            }

            if(returnRomvalue !== null && returnRomvalue !== undefined) {
                return returnRomvalue;
            }

        },
        blacklist = function(work, reason) {
            var cut = $('<div>').addClass('cut').html(work.html()),
                reason = '  (One or more romantic relationships) ',
                thisFold = fold.clone(),
                reasonContainer = thisFold.find('.reason');

            reasonContainer.html(reason);

            work.empty().append(thisFold, cut.hide());
            work.find('a.action').click(function() {
                var fold = $(this).closest('.fold'),
                    cut = fold.next('.cut');

                cut.add(fold.children('.'+toggleClass)).toggle();
                $(this).text(cut.is(':visible') ? 'Hide' : 'Unhide');
            })
        };

    works.each(function() {
        var reason = shouldBlacklist($(this));
        if (reason) {
            blacklist($(this), reason)
        }
    });

})(window.jQuery);