Gnome Extensions tweaks

this code opens extension pages in the new tab and changes sorting of the extensions list

当前为 2018-03-21 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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
// @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);
    });
})();