├── README.md
├── preview.png
└── script.js
/README.md:
--------------------------------------------------------------------------------
1 | # Steamunlocked
2 |
3 | With this script a notification will appear on the page when new games are released. It works on https://steamunlocked.net/all-games/. Makes use of window.localStorage to store the games currently present, so be careful not to have the option of deleting data when exiting the browser. The button UPDATE will add new games to local storage, the button CLEAR will clear the local storage.
4 | Game updates are handled: if a game receives an update (e.g. "CrossCode Free Download (v1.2.0.5)" --> "CrossCode Free Download (v1.4.1-6 & ALL DLC’s)") the script will consider it as a new entry, then will add it to the list.
5 |
6 |
7 | ## Version 1.0.1
8 | - Code reorganized for better readability
9 | - Added a CLEAR button to clear the tracked games list
10 | - Added total games count next to "All games (A-Z)"
11 |
12 | ## Version 1.0
13 | - Overlib support: scrolling the mouse over the link, an image preview of the game will appear. IT MAY TAKE SOME TIME TO RETRIEVE THE IMAGE.
14 |
15 | Initially written and used with tampermonkey ("http://tampermonkey.net/").
16 |
17 | This script may be subject to changes and updates over time.
18 |
19 | ## Preview
20 | 
21 |
--------------------------------------------------------------------------------
/preview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/N-O-E-D/Steamunlocked/da7098dd25b493011d0dd158efc72411682cc0fa/preview.png
--------------------------------------------------------------------------------
/script.js:
--------------------------------------------------------------------------------
1 | // ==UserScript==
2 | // @name Steamunlocked script newver
3 | // @namespace http://tampermonkey.net/
4 | // @version 1.0.1
5 | // @description Script that notices you if there are new games on the site
6 | // @author NOED
7 | // @match https://steamunlocked.net/all-games*/
8 | // @run-at document-start
9 | // @grant none
10 | // @require https://raw.githubusercontent.com/overlib/overlib/master/overlib.js
11 | // ==/UserScript==
12 |
13 |
14 | window.onload=function() {
15 |
16 | 'use strict';
17 |
18 |
19 | var numprev=window.localStorage.getItem("numprev"); //number of games before the execution of this script;
20 | var elements=document.getElementsByClassName("blog-content")[0].children[0].children; //list of elements (all games)
21 | var numactual=elements.length; //length of the list (# all games)
22 | var pos=document.getElementsByClassName("blog-content")[0]; //"All Games (A-Z)" banner
23 | console.log("#games before: " + numprev)
24 | console.log("#games now: " + numactual)
25 | document.getElementsByClassName("blog-content-title")[0].children[0].insertAdjacentText("beforeend"," ("+numactual+" games)");
26 |
27 | if(numprev!=null){
28 |
29 | var popgamescolumn=document.getElementsByClassName("col-lg-4")[0]; //"popular games" column element
30 | var infocolumn=document.createElement("div"); //new element for new games, to be inserted above "popular games" column
31 | infocolumn.className="col-lg-4";
32 | infocolumn.id="infocolumn";
33 |
34 | var listnew=document.createElement("ul"); //new list to be inserted. to add new elements to the list: listnew.appendchild(li), where li is an entry
35 | listnew.className="newgameslist";
36 |
37 | var nnew=0;
38 |
39 | //search:
40 | for(let element of elements){ //for each item of the global list (the "all games" one)...
41 | let link=element.children[0].href; //...take the link...
42 | let text=element.children[0].text; //...take the text...
43 | if(window.localStorage.getItem(text)==null){ //if it's not present in the local storage
44 | let entry=document.createElement("li"); //...add it to the list
45 | let content=document.createElement("a");
46 | content.text=text;
47 | content.href=link;
48 | content.style.color='#C6C6C6';
49 | fetchImageAndAttachOverlib(link,content);
50 | entry.appendChild(content);
51 | listnew.appendChild(entry);
52 | nnew++; //increment # of new games
53 | }
54 | }
55 | infocolumn.appendChild(listnew); //listnew contains all new games: useful at the pressure of the UPDATE button
56 | popgamescolumn.insertAdjacentElement("beforebegin",infocolumn); //add the new list above "popular games"
57 |
58 | infocolumn.insertAdjacentHTML("beforebegin",""+nnew+" new entries");
59 |
60 | //now let's handle the the local storage update...
61 | var updatebtn=document.createElement("button");
62 | updatebtn.innerHTML="UPDATE";
63 | updatebtn.style.backgroundColor='#000000';
64 | if(nnew==0){
65 | updatebtn.style.visibility = "hidden";
66 | }
67 | updatebtn.onclick=function(){
68 | let confirm=window.confirm("Are you sure you want to update the tracked games list?");
69 | if(confirm==true){ // if the user confirms...
70 | window.localStorage.setItem("numprev",numactual); //insert it into the local storage -> this script will check this variable every time
71 | insertElementsIntoLocalstorage();
72 | window.alert("New games added in the local storage!");
73 | location.reload();
74 | }
75 | }
76 | listnew.insertAdjacentElement("afterend",updatebtn); //add the button
77 |
78 | //...and the cleaning of the local storage
79 | var clearbtn=document.createElement("button");
80 | clearbtn.innerHTML="CLEAR";
81 | clearbtn.style.backgroundColor='#000000';
82 |
83 | clearbtn.onclick=function(){
84 | let confirm=window.confirm("Are you sure you want to clear the local storage (and don't want to track new games anymore)?");
85 | if(confirm==true){ // if the user confirms...
86 | window.localStorage.clear();
87 | window.alert("Local storage cleared!");
88 | location.reload();
89 | }
90 | }
91 | if(nnew==0){
92 | updatebtn.insertAdjacentElement("beforebegin",clearbtn); //add the button
93 | }
94 | else{
95 | updatebtn.insertAdjacentElement("afterend",clearbtn); //add a button
96 | }
97 | }
98 | else{ //no entries in the local storage = running this script the first time or entries deleted
99 | numprev=numactual; //if previous # games is not present, calculate it now.
100 | let confirm=window.confirm("No entries in the local storage.\nAdd entries?"); //ask before add entries, also for a manual verification by the user (F12->Application->localStorage)
101 | if(confirm==true){ // if the user confirms...
102 | insertElementsIntoLocalstorage(); //...add entries in the local storage
103 | window.localStorage.setItem("numprev",numprev);
104 | }
105 | }
106 |
107 | function insertElementsIntoLocalstorage(){
108 | for(let element of elements){
109 | let link=element.children[0].href;
110 | let text=element.children[0].text;
111 | window.localStorage.setItem(text,link); //add it into the local storage -> value updated if key already exists
112 | }
113 | }
114 |
115 | function fetchImageAndAttachOverlib(link,content){
116 | fetch(link).then(function(response){return response.text();})
117 | .then(function(html){
118 | let parser = new DOMParser();
119 | let doc = parser.parseFromString(html, 'text/html');
120 | let overImage = doc.getElementsByClassName("blog-content")[0].querySelector("img");
121 |
122 | if(overImage.src.startsWith("http")){
123 | overImage = "
"; //it just works: if src is of type "http...";
124 | }
125 | else if(overImage.src.startsWith("data")){
126 | overImage = "
"; //it just works: if src is of type "data.." (so take data-src)
127 | }
128 | else overImage="cannot retrieve image"; //else show an error
129 |
130 | //... add other cases in future...
131 |
132 | content.onmouseover = function(){overlib(overImage, WIDTH, 500, LEFT, VAUTO)}; //...and inflate it as overlib (first param of overlib(...) wants an img string element, not the src string
133 | content.onmouseout = function(){nd()};
134 | })
135 | .catch(function (err) {console.warn('Something went wrong.', err);});
136 | }
137 |
138 | };
139 |
--------------------------------------------------------------------------------