Skip to content

Commit c055615

Browse files
committed
Merge branch 'dev' into main
2 parents 3e570d1 + 12f32d3 commit c055615

4 files changed

Lines changed: 78 additions & 26 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Install [WFES Base](https://github.com/AlterTobi/WFES/raw/main/wfes-base.user.js
1414
## List of scripts
1515
* [showcase](https://github.com/AlterTobi/WFES/raw/main/wfes-showcase.user.js)
1616
- shows wayspot description and the game used for submitting
17+
![](./assets/showcase.png)
1718

1819
## Developer documentation
1920
Documentation for devs is available in the [Wiki](https://github.com/AlterTobi/Wayfarer-Extension-Scripts/wiki/WFES-Base).

assets/showcase.png

15.9 KB
Loading

wfes-base.user.js

Lines changed: 75 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ==UserScript==
22
// @name WFES - Base
33
// @namespace https://gitlab.com/fotofreund0815/WFES
4-
// @version 0.1.0
4+
// @version 0.2.1
55
// @description basic functionality for WFES
66
// @author fotofreund0815
77
// @match https://wayfarer.nianticlabs.com/*
@@ -12,32 +12,54 @@
1212
(function() {
1313
'use strict';
1414

15+
/* WFES data structures */
1516
const PREFIX = '/api/v1/vault/';
17+
const sStoreReview = 'wfes_Reviews';
1618

1719
window.wfes = {};
1820
window.wfes.showcase = {};
21+
window.wfes.review = {};
22+
window.wfes.review.decision = {};
1923

20-
// window.wfes.showcase;
24+
/* overwrite XHR */
2125

22-
let openOrig = window.XMLHttpRequest.prototype.open,
26+
let openOrig = window.XMLHttpRequest.prototype.open,
2327
sendOrig = window.XMLHttpRequest.prototype.send;
2428

2529
function openReplacement(method, url, async, user, password) {
2630
this._url = url;
27-
console.log( "WFES OPEN: ", method, url );
31+
this._method = method;
32+
// console.log( "WFES OPEN: ", method, url );
2833
this.addEventListener('load', handleLoadEvent);
2934
return openOrig.apply(this, arguments);
30-
}
35+
}
3136

32-
function sendReplacement(data) {
33-
if(this.onreadystatechange) {
34-
this._onreadystatechange = this.onreadystatechange;
35-
}
36-
//console.log( "WFES SEND: ", data );
37-
//console.dir( data );
38-
// this.onreadystatechange = onReadyStateChangeReplacement;
39-
return sendOrig.apply(this, arguments);
37+
function sendReplacement(daten) {
38+
let candidate, json;
39+
// handle only POST requests
40+
if ('POST' === this._method) {
41+
switch (this._url) {
42+
case PREFIX + 'review':
43+
json = JSON.parse(daten);
44+
candidate = window.wfes.review.sessionHist[json.id];
45+
window.wfes.review.decision.candidate = candidate;
46+
window.wfes.review.decision.decision = json;
47+
window.dispatchEvent(new Event("WFESReviewDecisionSent"));
48+
break;
49+
case PREFIX + 'skip':
50+
json = JSON.parse(daten);
51+
candidate = window.wfes.review.sessionHist[json.id];
52+
window.wfes.review.decision.candidate = candidate;
53+
json.skipped = true;
54+
window.wfes.review.decision.decision = json;
55+
window.dispatchEvent(new Event("WFESReviewDecisionSent"));
56+
break;
57+
default:
58+
break;
59+
}
4060
}
61+
return sendOrig.apply(this, arguments);
62+
}
4163

4264
function handleLoadEvent(e) {
4365
let json;
@@ -49,22 +71,52 @@
4971
window.wfes.showcase.list = json.result.showcase;
5072
window.dispatchEvent(new Event("WFESHomePageLoaded"));
5173
break;
74+
case PREFIX + 'review':
75+
if ('GET' === this._method) {
76+
json = JSON.parse(response);
77+
handleReviewData(json.result);
78+
}
79+
break;
80+
default:
81+
break;
5282
}
5383
} catch (e) {
54-
console.log(e);
84+
console.warn(e);
5585
}
5686
}
5787

58-
/*
59-
function onReadyStateChangeReplacement() {
60-
// PLACE HERE YOUR CODE FOR READYSTATECHANGE
61-
if(this._onreadystatechange) {
62-
return this._onreadystatechange.apply(this, arguments);
63-
}
64-
}
65-
*/
66-
6788
window.XMLHttpRequest.prototype.open = openReplacement;
6889
window.XMLHttpRequest.prototype.send = sendReplacement;
90+
91+
/* handle data */
92+
93+
//Useful to make comparing easier. Essentially this function iterates over all items
94+
//and uses it's unique ID as key and stores relevant values under that key.
95+
//This way on checking we can simply find the ID when looking at a current item
96+
function makeIDbasedDictionary(itemList){
97+
let dict = {};
98+
for (let i = 0; i < itemList.length; i++){
99+
let item = itemList[i];
100+
dict[item.id] = item;
101+
}
102+
return dict;
103+
}
104+
105+
function handleReviewData(result) {
106+
// save review data in ...pagedata and sessionstore
107+
let reviewSessionHist = JSON.parse(sessionStorage.getItem(sStoreReview)) || []
108+
window.wfes.review.sessionHist = makeIDbasedDictionary(reviewSessionHist);
109+
110+
if (undefined === window.wfes.review.sessionHist[result.id]) {
111+
reviewSessionHist.push(result);
112+
sessionStorage.setItem(sStoreReview,JSON.stringify(reviewSessionHist));
113+
window.wfes.review.sessionHist[result.id] = result;
114+
}
115+
116+
window.wfes.review.pageData = result;
117+
window.dispatchEvent(new Event("WFESReviewPageLoaded"));
118+
}
119+
120+
/* we are done :-) */
69121
console.log( "WFES BASE loaded");
70122
})();

wfes-showcase.user.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ msqzhMX9D7VJotwvKKA1oVMgNaNJDNsjZTvo2WdEpXjaryj2PFGizxWvVQjbPzdTzPg88biHDRZF\
6262
ao7gTYkYY4ufrWjxhNVUQhcNLyHFFPN89trIG7UviJSZLPv8Hdh37+8x2JqqqjJMj4GiMKaq9unf\
6363
IYqHgkTBHM2N/P+MPR7hIjB3OzN427/WvgQYAPTTeKqgtlNiAAAAAElFTkSuQmCC');
6464
}
65-
6665
`;
6766
headElem.appendChild(customStyleElem);
6867
}
@@ -72,7 +71,7 @@ IYqHgkTBHM2N/P+MPR7hIjB3OzN427/WvgQYAPTTeKqgtlNiAAAAAElFTkSuQmCC');
7271
// console.log( "WFES showDetails", details);
7372
let myDescID = "wfesDescrition";
7473
let myGameID = "wfesGame";
75-
74+
7675
if ( null === document.getElementById(myDescID)) {
7776
let descriptionText = document.createElement("div");
7877
descriptionText.setAttribute('id',myDescID);
@@ -90,7 +89,7 @@ IYqHgkTBHM2N/P+MPR7hIjB3OzN427/WvgQYAPTTeKqgtlNiAAAAAElFTkSuQmCC');
9089
gameLogo.setAttribute('id',myGameID);
9190
userBox.appendChild(gameLogo);
9291
}
93-
92+
9493
switch (details.discovererGame) {
9594
case '': // no logo
9695
klasse = 'bgNone';

0 commit comments

Comments
 (0)