Mark owned ScummVM Games

A simple aid for collecting ScummVM-supported games

Από την 29/11/2015. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name        Mark owned ScummVM Games
// @namespace   ssokolow.com
// @description A simple aid for collecting ScummVM-supported games
// @license MIT
// @version     3
// @require     https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
//
// @match       *://scummvm.org/compatibility/*
// @match       *://www.scummvm.org/compatibility/*
//
// @compatible  firefox Tested regularly under Greasemonkey.
// @compatible  chrome  Tested occasionally under Tampermonkey.
//
// @grant       GM_setValue
// @grant       GM_deleteValue
// @grant       GM_listValues
// ==/UserScript==

const OWNED_OPACITY = 0.3;
var owned_games = GM_listValues();

var toggleOwnership = function(e) {
    e.preventDefault();

    var $this = $(this);
    var game_id = $this.data('game_id');

    // Toggle based on what's displayed so that it will always act as the
    // user expects, regardless of changes since last reload
    if ($this.text() == '+') {
        $this.text('-');
        $this.closest('a').css('opacity', OWNED_OPACITY);
        GM_setValue(game_id, true);
    } else {
        $this.text('+');
        $this.closest('a').css('opacity', 1.0);
        GM_deleteValue(game_id);
    }
};

$('.content a').each(function() {
    var $this = $(this);

    // Extract the game ID for use in record-keeping
    var url = $(this).attr('href').split('/');
    var game_id = url[url.length-1] ? url[url.length-1] : url[url.length-2];

    // Craft a button to toggle ownership status
    var togglebutton = $('<span>', {title: "Toggle Owned"})
        .text(owned_games.indexOf(game_id) == -1 ? '+' : '-')
        .css({
            border: '1px solid black',
            borderRadius: 2,
            color: 'black',
            display: 'inline-block',
            fontWeight: 'bold',
            marginRight: 5,
            visibility: 'hidden',
            paddingLeft: 2,
            paddingRight: 2,
            textAlign: 'center',
            width: '1em',
        }).data('game_id', game_id)
        .click(toggleOwnership)
        .prependTo($this);

    // On-hover display in a manner which won't reposition the game title
    $this.hover(function() { togglebutton.css('visibility', 'visible'); },
                function() { togglebutton.css('visibility', 'hidden'); });

    // TODO: Profile alternatives like an x|y|z regexp or a popping iteration
    if (owned_games.indexOf(game_id) !== -1){
        $this.css('opacity', OWNED_OPACITY);
    }
});