Better Secpaper

better secpaper (when it works).

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Better Secpaper
// @namespace    http://bnkr.tk/
// @version      0.5
// @description  better secpaper (when it works).
// @author       bnkr
// @match        http://secpaper.cn/*
// @match        https://secpaper.cn/*
// @run-at       document-start
// @grant        none
// ==/UserScript==

(function() {
    var init = function () {
        const sum_values = cnt => Object.values(cnt).reduce((a,b) => a + b, 0);
        const get_search_hits = cnt_str => sum_values(JSON.parse(cnt_str.replaceAll("'", '"')));

        $.fn.dataTableExt.oSort["counter-desc"] = function (x, y)
        {
            if (get_search_hits(x) < get_search_hits(y)) {
                return 1;
            }
            return -1;
        };

        $.fn.dataTableExt.oSort["counter-asc"] = function (x, y)
        {
            if (get_search_hits(x) < get_search_hits(y)) {
                return -1;
            }
            return 1;
        };
    };

    var init_table = function () {
        return $('#example').dataTable({
            "retrieve": true,
            "columnDefs": [
                { "type": "counter", targets: 4 }
            ]
        })
    };

    var f_checkbox = function () {
        document.addEventListener('DOMContentLoaded', () => {
            $('#conf input').each(function () {
                this.checked = true;
            });
        }, false);
    };

    var f_checkbox2 = function() {
        // zhang's version
        var arr = document.getElementById('conf');
        arr = arr.getElementsByTagName("input");
        for (var i = 0; i < arr.length; i++) {
            arr[i].checked = true;//选中
        }
    }

    var f_order = function () {
        // disable any script in body part from running
        const ob = new MutationObserver((_, observer) => {
            //const tag = document.querySelector('.container script');
            const tag = document.querySelector('body script');
            if (tag) {
                tag.remove();
                //observer.disconnect();
            }
        });
        ob.observe(document.documentElement, { childList: true, subtree: true });

        // inject our own table generation functions
        document.addEventListener('DOMContentLoaded', () => {
            ob.disconnect();
            init();
            init_table();
        }, false);
    };

    var pathname = window.location.pathname;
    var page_f_runner = {
        '/': f_checkbox,
        '/advance': f_checkbox,
        '/result': f_order,
        '/advance_result': f_order
    }[pathname]();
})();