Gnome Extensions tweaks

this code opens extension pages in the new tab and changes sorting of the extensions list (extensions.gnome.org)

目前為 2018-03-31 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name            Gnome Extensions tweaks
// @namespace       almaceleste
// @version         0.3
// @description     this code opens extension pages in the new tab and changes sorting of the extensions list (extensions.gnome.org)
// @description:ru  этот код открывает страницы расширений в новой вкладке и изменяет сортировку списка расширений
// @author          (ɔ) Paola Captanovska
// @license         GPL-3.0+; http://www.gnu.org/licenses/gpl-3.0.txt
// @icon            https://cdn1.iconfinder.com/data/icons/system-shade-circles/512/gnome-128.png

// @homepageURL     https://greasyfork.org/en/users/174037-almaceleste
// @homepageURL     https://openuserjs.org/users/almaceleste
// @homepageURL     https://github.com/almaceleste/userscripts
// @supportURL      https://github.com/almaceleste/userscripts/issues

// @require         https://openuserjs.org/src/libs/sizzle/GM_config.js
// @grant           GM_getValue
// @grant           GM_setValue
// @grant           GM_registerMenuCommand

// @match           https://extensions.gnome.org/
// @match           https://extensions.gnome.org/#sort*
// ==/UserScript==

// ==OpenUserJS==
// @author almaceleste
// ==/OpenUserJS==

const extensionsdiv = 'extensions-list';
const extensionslist = 'extensions';
const extensionlink = 'a.title-link';
const navbarbtn = '#navbar-wrapper a:contains("Extensions")';

const windowcss = '#getweaksCfg {background-color: lightblue;} #getweaksCfg .reset_holder {float: left; position: relative; bottom: -1em;} #getweaksCfg .saveclose_buttons {margin: .7em;}';
const iframecss = 'height: 19.7em; width: 30em; border: 1px solid; border-radius: 3px; position: fixed; z-index: 999;';

GM_registerMenuCommand('Gnome Extensions tweaks', opencfg);

function opencfg()
{
	GM_config.open();
	getweaksCfg.style = iframecss;
}

GM_config.init(
{
    id: 'getweaksCfg',
    title: 'Gnome Extensions tweaks Settings',
    fields:
    {
        extensionlink:
        {
            section: ['Link types', 'Choose link types to open in new tab'],
            label: 'extension links',
            labelPos: 'right',
            type: 'checkbox',
            default: true,
        },
        sorting:
        {
            section: ['List sorting', 'Choose list sorting'],
            label: 'sorting links',
            labelPos: 'left',
            type: 'select',
            options: ['name', 'recent', 'downloads', 'popularity'],
            default: 'recent',
        },
    },
    css: windowcss,
    events:
    {
        save: function() {
            GM_config.close();
        }
    },
});

(function() {
    'use strict';

    if(GM_config.get('extensionlink')) {
        $(document).ready(function(){
            var targetNode, callback, observer;
            var config = {childList: true}; //, subtree: true};
            targetNode = document.getElementById(extensionsdiv);
            callback = function(e){
                if(e.nodeName == 'UL' && e.className == extensionslist){
                    observer.disconnect();
                    $(extensionlink).attr('target', '_blank');
                }
            };

            observer = new MutationObserver(function(mutations) {
                for(var m of mutations) {
                    m.addedNodes.forEach(callback);
                }
            });

            observer.observe(targetNode, config);
        });
    }

    var sorting = '#sort=' + GM_config.get('sorting');
    $(navbarbtn).each(function(){
        var href = $(this).attr('href');
        $(this).attr('href', href + sorting);
    });
})();