Nyaa Helper

nyaa helper

Pada tanggal 18 September 2018. Lihat %(latest_version_link).

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Nyaa Helper
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  nyaa helper
// @author       Yich
// @include        https://sukebei.nyaa.si/*
// @grant          GM_openInTab
// @grant       GM_addStyle
// @grant       GM_getResourceText
//@require https://code.jquery.com/jquery-3.3.1.min.js
//@require https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.2.5/jquery.fancybox.min.js
// @resource    customCSS https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.2.5/jquery.fancybox.min.css
//@require https://use.fontawesome.com/releases/v5.0.8/js/solid.js
//@require https://use.fontawesome.com/releases/v5.0.8/js/fontawesome.js
//@run-at  document-end
// ==/UserScript==

//====================文章列表=============================
if( !UrlContains("view")){
    var articles = $(".table-responsive table tr");
    var DownloadCount = 100;//defaultDownloadcount的預設值
    //下載數量若超過此值,就標上success的class
     $("#navbar").append("<ul class=\"nav navbar-nav\" style=\"margin-top:10px;margin-right:5px;\">  \
                         <input type=\"number\" id=\"defaultDownloadcount\" value="+ DownloadCount +" placeholder=\"高亮指定下載數\" /></ul>");
    document.getElementById ("defaultDownloadcount").addEventListener("input",  function(){
        HighLightArticle(articles,this.value);
    }, false);

    HighLightArticle(articles,$("#defaultDownloadcount").val());

    //加入按鈕
    $("#navbar").append("<ul class=\"nav navbar-nav\" style=\"margin-top:7px\"><li><button type=\"button\"  id=\"btnOpenAll\" class=\"btn btn-success\">開啟高亮文章</button></li></ul>");
    document.getElementById ("btnOpenAll").addEventListener ("click", OpenArticles, false);
}
    //將瀏覽數超過指定數量的文章標上success
function HighLightArticle(articles,DownLoadCount){
        //移除所有class
    articles.removeClass();
    articles.each(function() {
        var currentDownloadCount = $(this).find('td:last').html();
        if(parseInt(currentDownloadCount) >= parseInt(DownLoadCount)){
             $(this).addClass("success").addClass("OverBrowseCount");
        }
    });
}
//開啟超過指定瀏覽數的文章
function OpenArticles(){
    $(".OverBrowseCount").each(function() {
        var url = document.URL + $(this).find("td:eq(1)>a").attr("href");
        GM_openInTab( url, true );
    });
}
//====================文章內文=============================
if(UrlContains("view")){
        //取得description區塊的html
        var html = $("#torrent-description").html();
        var rawHtml = decodeEntities(html);
        //找出區塊裡的連結
        var reg = /((?:\w+):\/\/([\w@][\w.:@-]+)\/?[\w\.?=%&=\-@\/$,]*)/g;
        var url;
        while (url = reg.exec(rawHtml)) {
            if(!url[1].includes('offkab')){
                //彈出視窗
                GM_openInTab( url[1], true );
                break;
            }
        }

}

//=======================utility======================

function UrlContains(urlfragment){
	return document.URL.indexOf(urlfragment) != -1;
}

//url decode
function decodeEntities(encodedString) {
    var textArea = document.createElement('textarea');
    textArea.innerHTML = encodedString;
    return textArea.value;
}