Instantly share code, notes, and snippets.
Last active
April 1, 2023 07:15
-
Star
(1)
1
You must be signed in to star a gist -
Fork
(1)
1
You must be signed in to fork a gist
-
Save dimateos/53aa71ce384b4c6d7086848d709c013c to your computer and use it in GitHub Desktop.
userscript - [DEPRECATED] Humble Bundle - Steam Links Adder (Updated + button)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name HB - Steam Links Adder | |
// @icon https://humblebundle-a.akamaihd.net/static/hashed/47e474eed38083df699b7dfd8d29d575e3398f1e.ico | |
// @namespace Royalgamer06 | |
// @version 1.2.3 | |
// @description Adds steam links to Humble Bundle games on interface button press (based on https://greasyfork.org/en/scripts/27373-humble-bundle-steam-links-adder/code) | |
// @author Revadike | |
// @contributor redion1992 | |
// @contributor dimateos | |
// @include *://www.humblebundle.com/subscription/home* | |
// @include *://www.humblebundle.com/games/* | |
// @include *://www.humblebundle.com/home/* | |
// @include *://www.humblebundle.com/downloads* | |
// @grant GM_xmlhttpRequest | |
// @grant GM_addStyle | |
// @run-at document-idle | |
// @connect api.steampowered.com | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.js | |
// ==/UserScript== | |
//you could add the store too | |
// @include *://www.humblebundle.com/store/* | |
// ==Configuration== | |
//button style | |
GM_addStyle (` | |
#myContainer { | |
position: fixed; | |
bottom: 0; | |
left: 0; | |
font-size: 20px; | |
background: teal; | |
border: 3px outset black; | |
margin: 5px; | |
opacity: 0.9; | |
z-index: 1100; | |
padding: 5px 20px; | |
} | |
#myButton { | |
cursor: pointer; | |
} | |
#myContainer p { | |
color: red; | |
font-size: 22px; | |
} | |
` ); | |
//edit to fit future web changes | |
const selectors = [".entity-title", | |
".deal-title", | |
".product-name", | |
".text-holder > h2", | |
".product-title > h2", | |
"h1[data-entity-kind=product]", | |
".front-page-art-image-text", // ".desktop:has(.hb-steam) .dd-image-box-caption", | |
".content-choice-title", | |
".humble-original-title", | |
".game-name > h4", | |
".sr-key-heading > span"]; | |
// ==/Configuration== | |
// ==Code== | |
//--- Style our newly added elements using CSS. | |
GM_addStyle('.bundle-info-text a { visibility: visible; }'); | |
this.$ = this.jQuery = jQuery.noConflict(true); | |
const selector = selectors.join(":not(.steamified):not(a):not(:has(a)), ") + ":not(.steamified):not(a):not(:has(a))"; | |
function steamify(titleElem, applist) { | |
// console.log("TEST: " + titleElem); | |
$(titleElem).addClass("steamified"); | |
setTimeout(() => { | |
let title = $(titleElem).text().toLowerCase().replace(/locked content|\(early access\)|\(pre\-order\)|\:|\-|\–|\\|\/|\™|\®| |\’|\`|\'|\.|\?|\!/g, "").trim(); | |
let obj = applist.filter(v => v.name.toLowerCase().replace(/\:|\-|\–|\\|\/|\™|\®| |\’|\`|\'|\.|\?|\!/g, "").trim() === title)[0]; | |
if (obj) { | |
console.log("MATCH: " + title); | |
$(titleElem).wrapInner("<a style='color: TEAL; z-index: -1;' href='http://store.steampowered.com/app/" + obj.appid + "/'></a>"); | |
} else { | |
title = $(titleElem).text().toLowerCase().replace(/locked content|\(early access\)|\(pre\-order\)|\-|\–|\\|\/|\™|\®| |\’|\`|\'|\.|\?/g, "").split(":")[0].split("!")[0].trim(); | |
obj = applist.filter(v => v.name.toLowerCase().replace(/\:|\-|\–|\\|\/|\™|\®| |\’|\`|\'|\.|\?|\!/g, "").trim() === title)[0]; | |
if (obj) { | |
console.log("MATCH: " + title); | |
$(titleElem).wrapInner("<a style='color: TEAL; z-index: -1;' href='http://store.steampowered.com/app/" + obj.appid + "/'></a>"); | |
} | |
} | |
}, 0); | |
} | |
function addLinks1(button) { | |
GM_xmlhttpRequest({ | |
method: "GET", | |
url: "https://api.steampowered.com/ISteamApps/GetAppList/v2/", | |
onload: response => { | |
const responseJSON = JSON.parse(response.responseText); | |
console.log("Response API V2 JSON: ", responseJSON); | |
const applist = responseJSON.applist.apps; | |
console.log("Applist ready: ", applist); | |
console.log("Selected: ", $(selector)); | |
if (applist.length == 0) { | |
var but = document.getElementById ("myContainer"); | |
but.innerHTML = '<b><i><p> API: EMPTY V2 LIST </p><p> > TESTING V1 LIST... </p></i></b>'; | |
addLinks2(button); | |
return; | |
} | |
setTimeout(function(){ button.remove(); }, 5000); | |
$(document).ready(() => setInterval(() => $(selector).each((i, e) => steamify(e, applist)), 100)); | |
} | |
}); | |
} | |
function addLinks2(button) { | |
GM_xmlhttpRequest({ | |
method: "GET", | |
url: "https://api.steampowered.com/ISteamApps/GetAppList/v1/", | |
onload: response => { | |
const responseJSON = JSON.parse(response.responseText); | |
console.log("Response API V1 JSON: ", responseJSON); | |
const applist = responseJSON.applist.apps.app; | |
console.log("Applist ready: ", applist); | |
console.log("Selected: ", $(selector)); | |
if (applist.length == 0) { | |
var but = document.getElementById ("myContainer"); | |
but.innerHTML = '<b><i><p> API: EMPTY V1 LIST </p><p> > TOO MANY REQUESTS? </p></i></b>'; | |
return; | |
} | |
setTimeout(function(){ button.remove(); }, 5000); | |
$(document).ready(() => setInterval(() => $(selector).each((i, e) => steamify(e, applist)), 100)); | |
} | |
}); | |
} | |
/*--- Create a button in a container div. It will be styled and positioned with CSS. */ | |
var zNode = document.createElement ('div'); | |
zNode.innerHTML = '<button id="myButton" type="button">' | |
+ 'Add links</button>' | |
; | |
zNode.setAttribute ('id', 'myContainer'); | |
document.body.appendChild (zNode); | |
//--- Activate the newly added button. | |
document.getElementById ("myButton").addEventListener ( | |
"click", ButtonClickAction, false | |
); | |
function ButtonClickAction (zEvent) { | |
var but = document.getElementById ("myContainer"); | |
but.innerHTML = '<p><b><i> ADDING... </i></b></p>' | |
addLinks1(but); | |
} | |
// ==/Code== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Original thread :)