WykopSeen

Add Seen button to hide seen wykops

目前為 2015-01-04 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         WykopSeen
// @namespace    http://www.wykop.pl/
// @require      http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @version      0.4
// @description  Add Seen button to hide seen wykops
// @author       axem.pl
// @match        http://www.wykop.pl/
// @match        http://www.wykop.pl/link/*
// @match        http://www.wykop.pl/wykopalisko/*
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_deleteValue
// ==/UserScript==

var jq = this.$ = this.jQuery = jQuery.noConflict(true);
var seenWykopClass = 'seen';

function eachLi() {
    var self = jq(this);
    var parent = self.parent();
    var btn = jq('<button class=\'seen-btn\'></button>');
    var href = self.find('h2 a').attr('href');
    
    function getSeenBtnText() {
        if (self.hasClass(seenWykopClass)) {
            return 'UNSEE';
        } else {
            return 'SEEN';
        }
    }
    function btnOnClick() {
        self.toggleClass(seenWykopClass);
        btn.text(getSeenBtnText());
        if (self.hasClass(seenWykopClass)) {
            GM_setValue(href, 1);
            parent.append(self);
        } else {
            GM_deleteValue(href);
            parent.prepend(self);
        }
    }
    if (GM_getValue(href)) {
        self.addClass(seenWykopClass);
        parent.append(self);
    }
    
    btn.text(getSeenBtnText());
    btn.on("click", btnOnClick);
    self.children('div').append(btn);   
}
function cssRules() {
    var rules = [
        'li.seen { background: lightgray }',
        'li.seen * { color: gray !important }',
        'li.seen .diggbox { display: none }',
        'li.seen .media-content { display: none }',
        'li.seen .fix-tagline { display: none }',
        'li.seen .description { display: none }',
        'li.seen .elements { display: none }',
        'li.seen .article { min-height: 0 }',
        '.seen-btn { position: absolute; top: 5px; right: 5px; z-index: 9999 }'
    ];
    return rules.join('\n');
}
function seenFullBtn() {
    var btn = jq('<li><a class=\'affect\' href=\'#\'><i class=\'fa fa-star\'></i><span></span></a>');
    var href = document.location.toString().split('#');
    
    function refreshBtnText() {
        if (GM_getValue(href)) {
            btn.find('span').text('UNSEE');
        } else {
            btn.find('span').text('SEEN');
        }
    }
    
    btn.find('a').on('click', function () {
        if (btn.find('span').text() === 'SEEN') {
            GM_setValue(href, 1);
        } else {
            GM_deleteValue(href);
        }
		refreshBtnText();
        event.preventDefault();
        return false;
    });

    refreshBtnText();
    
    jq('.article.fullview .actions ul').append(btn);
}
function exec() {
    jq(document.body).append(jq('<style type=\'text/css\'></style>').html(cssRules()));
    jq('#itemsStream li').each(eachLi);
    seenFullBtn();
}
exec();