Moochable book filter for Bookmooch mobile

Adds a button to toggle the display of unavailable books on the wishlist and search results pages.

当前为 2014-11-09 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Moochable book filter for Bookmooch mobile 
// @namespace    bookmooch
// @version      0.1
// @description  Adds a button to toggle the display of unavailable books on the wishlist and search results pages.
// @include      /^http://(fr|jp|pt)\.bookmooch\.com/mobile/m/(wishlist|search_do).*$/
// @include      /^http://bookmooch\.(com|de|es|it|se)/mobile/m/(wishlist|search_do).*$/
// @grant        none
// ==/UserScript==

window.show_moochable = false;

var heart = document.createElement("span");
heart.appendChild(document.createTextNode("\u2665 "));
heart.setAttribute("id", "heartToggle");
heart.setAttribute("title", "Toggle moochable filter");

var header = document.getElementById('pageTitle');
header.insertBefore(heart, header.firstChild);

heart.addEventListener("click", toggleFilter, true);

function toggleFilter() {
    var lis = document.getElementsByTagName('li');
    window.show_moochable = !window.show_moochable;
    var display = window.show_moochable ? 'none' : 'block';
    for (i = 0; i < lis.length; i++) {
        if (lis[i].firstChild.firstChild.textContent != '\u2665')
            lis[i].style.display = display;
    }
    document.getElementById("heartToggle").style.color = window.show_moochable ? "#FF0000" : "inherit";    
}