// ==UserScript==
// @name Steam Free License Helper
// @author McKack
// @description 脚本来源:https://steamcn.com/t139360-1-1
// @namespace http://steamcommunity.com/id/mckack
// @version 0.36
// @description Adds buttons to SteamDB and your Steam licenses page to easily install free on demand or no cost packages.
// @match https://store.steampowered.com/account/licenses/*
// @match https://steamdb.info/search/*
// @grant GM_log
// @grant GM_getValue
// @grant GM_setValue
// @downloadURL https://update.greasyfork.icu/scripts/29891/Steam%20Free%20License%20Helper.user.js
// @updateURL https://update.greasyfork.icu/scripts/29891/Steam%20Free%20License%20Helper.meta.js
// ==/UserScript==
// Updated 2015-08-26 08:34 CET
// Borrow jQuery from current site
$ = unsafeWindow.jQuery;
// -------------------- SteamDB page --------------------
if( location.href.match( /^https:\/\/steamdb\.info\/search\/.*sub_keyname.*$/ ) ) {
// Fetch and set type of subs search if relevant
var linkimg = '';
if( location.href.match( /.*keyvalue=12.*/ ) ) {
var sflh_jumpto = 'No Cost subs or your ' +
'Steam Account Licenses page ' + linkimg;
var sflh_type = 'Free on Demand';
var sflh_typeID = 'sflh_fods';
} else if( location.href.match( /.*keyvalue=0.*/ ) ) {
var sflh_jumpto = 'Free on Demand subs or your ' +
'Steam Account Licenses page ' + linkimg;
var sflh_type = 'No Cost';
var sflh_typeID = 'sflh_nocs';
} else {
var sflh_jumpto = 'Free on Demand subs, ' +
'No Cost subs or your ' +
'Steam Account Licenses page ' + linkimg;
};
// DOM-to-Userscript functions
unsafeWindow.sflh_update = function() {
console.clear();
localStorage.sflh_trailerschk = $( '#trailers' ).is( ':checked' ) ? 'checked ' : '';
localStorage.sflh_demoschk = $( '#demos' ).is( ':checked' ) ? 'checked ' : '';
//localStorage.sflh_idsonlychk = $( '#idsonly' ).is( ':checked' ) ? 'checked ' : '';
var sflh_list = $( '#table-sortable > tbody' ).text( ).replace( /(\d{1,6})\n(.*)\n(12|0)\n.*ago\n*/igm, "$1, //$2\n" ).replace( /0, \/\/Steam\n/igm, '' );
if ( localStorage.sflh_trailerschk === '' ) {
sflh_list = sflh_list.replace( /\d{2,6},\s\/\/.*(((\s|\()ESRB.*|(\s|\()PEGI.*)|(\s|_)tr?aii?ler(\s\w*|.*USK)?(..\sNew|\sKingdom|2\s\w*)?|\steaser.?|dev.diary.*|TV.spot.*|Meet\sthe\s\w*|gameplay|ged\strailed)$\n/igm, '' );
};
if ( localStorage.sflh_demoschk === '' ) {
sflh_list = sflh_list.replace( /\d{2,6},\s\/\/.*(Demo\s?\d?|07\sDemo.*)$\n/igm, '' );
};
//if ( localStorage.sflh_idsonlychk !== '' ) {
// sflh_list = sflh_list.replace( /(\d{2,6},).*?$\n?/igm, '$1' );
//};
sflh_list = sflh_list.replace( /(\d{2,6},).*?$\n?/igm, '$1' );
//var sflh_listcount = $( '#idsonly' ).is( ':checked' ) ? sflh_list.split( ',' ).length - 1 : sflh_list.split( ', //' ).length - 1;
var sflh_listcount = sflh_list.split( ',' ).length - 1;
GM_setValue( sflh_typeID, sflh_list.substr( 0, sflh_list.lastIndexOf( ',' ) ) + sflh_list.substr( sflh_list.lastIndexOf( ',' ) + 1,sflh_list.length ) );
console.log( '//' + sflh_listcount + ' entries' + GM_getValue( sflh_typeID ) );
alert(sflh_listcount + ' entries added to Steam Free License Helper\'s list of ' + sflh_type + ' subs!');
};
// Buttons
var sflh_btns = $( '' +
'Include trailers ? ' +
'Include demos ? ' +
//'IDs only »' +
'' +
'' );
// Insert stuff
if ( sflh_typeID === 'sflh_fods' || sflh_typeID == 'sflh_nocs' ) {
$( 'div.container > div.panel > div' ).replaceWith( '