Skip to content

Commit

Permalink
Merge branch 'main' into private
Browse files Browse the repository at this point in the history
  • Loading branch information
AlterTobi committed Nov 10, 2023
2 parents c061a5e + 141b801 commit c43fe95
Show file tree
Hide file tree
Showing 9 changed files with 1,438 additions and 952 deletions.
1,482 changes: 744 additions & 738 deletions wayfarer-keyboard-review.user.js

Large diffs are not rendered by default.

179 changes: 94 additions & 85 deletions wayfarer-open-in.user.js

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions wayfarer-reverse-image-search.user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ==UserScript==
// @name Wayfarer Reverse Image Search
// @version 0.3.0
// @version 0.4.0
// @description Add reverse image search links to Wayfarer
// @namespace https://github.com/tehstone/wayfarer-addons
// @downloadURL https://github.com/tehstone/wayfarer-addons/raw/main/wayfarer-reverse-image-search.user.js
Expand Down Expand Up @@ -69,11 +69,12 @@
});

const checkReviewType = result => awaitElement(() => (
document.querySelector('app-should-be-wayspot') ||
document.getElementById('check-duplicates-card') ||
document.querySelector('app-review-photo')
)).then(ref => {
console.log("checkReviewType")
switch (ref.tagName) {
case 'APP-SHOULD-BE-WAYSPOT':
case 'WF-REVIEW-CARD':
awaitElement(() => document.querySelector('#check-duplicates-card nia-map'))
.then((ref) => {
addImageSearchLinks(ref, result);
Expand All @@ -91,14 +92,15 @@
const addImageSearchLinks = (before, data) => {
const mainUrl = encodeURIComponent(`${data['imageUrl']}`);
const mainSearchUrl = `https://lens.google.com/uploadbyurl?url=${mainUrl}`
addLink(mainSearchUrl, 'div.review-cards--inner:nth-child(1) > app-should-be-wayspot:nth-child(1) > wf-review-card:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(2)');
addLink(mainSearchUrl, 'app-photo-b.nomination-info-review-card > wf-review-card-b:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(2)');

const supportingUrl = encodeURIComponent(`${data['supportingImageUrl']}`);
const supportingSearchUrl = `https://lens.google.com/uploadbyurl?url=${supportingUrl}`
addLink(supportingSearchUrl, '.supporting-info-review-card > wf-review-card:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(2)');
addLink(supportingSearchUrl, 'app-supporting-info-b.nomination-info-review-card > wf-review-card-b:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(2)');
}

const addLink = (url, selector) => {
console.log("addLink ")
const insertBeforeEl = document.querySelector(selector);
if (insertBeforeEl !== null && insertBeforeEl !== undefined) {
const linkSpan = document.createElement('span');
Expand Down
260 changes: 191 additions & 69 deletions wayfarer-review-counter.user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ==UserScript==
// @name Wayfarer Review Counter
// @version 0.2.7
// @version 0.4.1
// @description Add review counter to Wayfarer
// @namespace https://github.com/tehstone/wayfarer-addons
// @downloadURL https://altertobi.github.io/tehstone-wayfarer-addons/wayfarer-review-counter.user.js
Expand Down Expand Up @@ -31,63 +31,164 @@

(function() {

const CURRENT_EVENT = {
from: Date.parse('2023-05-24T12:00Z'),
to: Date.parse('2023-06-09T19:00Z'),
const CURRENT_EVENT =
{
from: Date.parse('2023-09-27T19:00Z'),
to: Date.parse('2023-10-06T19:00Z'),
label: 'Challenge:',
color: 'goldenrod',
currentValid: -1,
initialized: false,
parts: [
{
label: '🇪🇸',
regions: ['ES', 'IC', 'EA'],
from: Date.parse('2023-05-24T12:00Z'),
to: Date.parse('2023-05-30T22:27Z'),
label: '🇮🇹',
regions: ['IT'],
from: Date.parse('2023-09-27T19:00Z'),
to: Date.parse('2023-10-04T19:00Z'),
counter: 0
},
{
label: '🇫🇷',
regions: ['FR'],
from: Date.parse('2023-09-27T19:00Z'),
to: Date.parse('2023-10-04T19:00Z'),
counter: 0
},
{
label: '🇮🇩',
regions: ['ID'],
from: Date.parse('2023-05-30T22:27Z'),
to: Date.parse('2023-06-02T00:06Z'),
label: '🇩🇪',
regions: ['DE_BB','DE_BY','DE_BE','DE_BW','DE_HB','DD_HE','DE_HH','DE_MV','DE_NI','DD_NW','DE_RP','DE_SH','DD_SL','DE_SN','DE_ST','DE_TH'],
from: Date.parse('2023-09-27T19:00Z'),
to: Date.parse('2023-10-04T19:00Z'),
counter: 0
},
{
label: '🇧🇷',
regions: ['BR'],
from: Date.parse('2023-06-02T00:06Z'),
to: Date.parse('2023-06-04T18:33Z'),
label: '🇬🇧',
regions: ['GB'],
from: Date.parse('2023-09-27T19:00Z'),
to: Date.parse('2023-10-04T19:00Z'),
counter: 0
},
{
label: '🇩🇰',
regions: ['DK'],
from: Date.parse('2023-09-27T19:00Z'),
to: Date.parse('2023-10-04T19:00Z'),
counter: 0
},
{
label: '🇸🇪',
regions: ['SE'],
from: Date.parse('2023-09-27T19:00Z'),
to: Date.parse('2023-10-04T19:00Z'),
counter: 0
},
{
label: '🇨🇭',
regions: ['CH'],
from: Date.parse('2023-09-27T19:00Z'),
to: Date.parse('2023-10-04T19:00Z'),
counter: 0
},
{
label: '🇮🇳',
regions: ['IN'],
from: Date.parse('2023-06-04T18:33Z'),
to: Date.parse('2023-06-05T22:01Z'),
label: '🇦🇹',
regions: ['AT'],
from: Date.parse('2023-09-27T19:00Z'),
to: Date.parse('2023-10-04T19:00Z'),
counter: 0
},
{
label: '🇪🇸',
regions: ['ES'],
from: Date.parse('2023-09-27T19:00Z'),
to: Date.parse('2023-10-04T19:00Z'),
counter: 0
},
{
label: '🗺️',
regions: ['ES', 'IC', 'EA', 'IN', 'BR', 'ID'],
from: Date.parse('2023-06-05T22:01Z'),
to: Date.parse('2023-06-07T23:59Z'),
regions: ['IT', 'FR', 'DE_BB','DE_BY','DE_BE','DE_BW','DE_HB','DD_HE','DE_HH','DE_MV','DE_NI','DD_NW','DE_RP','DE_SH','DD_SL','DE_SN','DE_ST','DE_TH', 'GB', 'DK', 'SE', 'ES', 'AT', 'CH'],
from: Date.parse('2023-09-27T19:00Z'),
to: Date.parse('2023-10-04T19:00Z'),
counter: 0
}
]
};

const PAST_EVENTS = [
{
from: Date.parse('2023-06-16T19:00Z'),
to: Date.parse('2023-09-27T19:00Z'),
label: 'Challenge:',
color: 'goldenrod',
currentValid: -1,
initialized: false,
parts: [
{
label: '🗺️',
regions: ['Q3_ATL', 'Q3_CHI', 'Q3_HAM'],
from: Date.parse('2023-06-16T19:00Z'),
to: Date.parse('2023-09-27T19:00Z'),
counter: 0
}
]
},
{
from: Date.parse('2023-05-24T12:00Z'),
to: Date.parse('2023-06-09T19:00Z'),
label: 'Challenge:',
color: 'goldenrod',
currentValid: -1,
initialized: false,
parts: [
{
label: '🇪🇸',
regions: ['ES', 'IC', 'EA'],
from: Date.parse('2023-05-24T12:00Z'),
to: Date.parse('2023-05-30T22:27Z'),
counter: 0
},
{
label: '🇮🇩',
regions: ['ID'],
from: Date.parse('2023-05-30T22:27Z'),
to: Date.parse('2023-06-02T00:06Z'),
counter: 0
},
{
label: '🇧🇷',
regions: ['BR'],
from: Date.parse('2023-06-02T00:06Z'),
to: Date.parse('2023-06-04T18:33Z'),
counter: 0
},
{
label: '🇮🇳',
regions: ['IN'],
from: Date.parse('2023-06-04T18:33Z'),
to: Date.parse('2023-06-05T22:01Z'),
counter: 0
},
{
label: '🗺️',
regions: ['ES', 'IC', 'EA', 'IN', 'BR', 'ID'],
from: Date.parse('2023-06-05T22:01Z'),
to: Date.parse('2023-06-07T23:59Z'),
counter: 0
}
]
}
];

/**
* Overwrite the open method of the XMLHttpRequest.prototype to intercept the server calls
*/
(function (open) {
XMLHttpRequest.prototype.open = function (method, url) {
if (url == '/api/v1/vault/review') {
if (method == 'GET') {
if (method == 'GET') {
if (url == '/api/v1/vault/review' || url == '/api/v1/vault/home') {
this.addEventListener('load', injectCounter, false);
} else if (method == 'POST') {
this.addEventListener('load', incrementCounter, false);
}
} else if (method == 'POST') {
this.addEventListener('load', incrementCounter, false);
}
open.apply(this, arguments);
};
Expand All @@ -111,8 +212,11 @@
return;
}

const div = document.createElement('div');
div.className = 'wayfarerrctr';
let counterDiv = document.getElementById("counterDiv");
if (counterDiv === null) {
const div = document.createElement('div');
div.className = 'wayfarerrctr';
div.id = 'counterDiv';

let countLabel = document.createElement('p');
countLabel.textContent = 'Review count: ';
Expand All @@ -126,18 +230,19 @@
sessionStorage.setItem('wfrcCounter', 1);
counter.textContent = 1;
}
}

countLabel.addEventListener('click', confirmReset);
counter.addEventListener('click', confirmReset);

countLabel.addEventListener('click', confirmReset);
counter.addEventListener('click', confirmReset);

const container = ref.parentNode.parentNode;
container.appendChild(div);
const container = ref.parentNode.parentNode;
container.appendChild(div);
}

const now = Date.now();
const windowRef = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window;
if (CURRENT_EVENT && now >= CURRENT_EVENT.from && now <= CURRENT_EVENT.to && windowRef.wft_plugins_api && windowRef.wft_plugins_api.openIn) {
CURRENT_EVENT.currentValid = -1;
console.log("rc")
const WFTApi = windowRef.wft_plugins_api;
const response = this.response;
const json = JSON.parse(response);
Expand All @@ -154,45 +259,49 @@
}
}
const renderEventCounter = () => {
const div = document.createElement('div');
div.classList.add('wayfarerrctr_event');
let countLabel = document.createElement('p');
countLabel.textContent = CURRENT_EVENT.label;
const evTable = document.createElement('table');
const evRow = document.createElement('tr');
evTable.appendChild(evRow);
div.appendChild(countLabel);
div.appendChild(evTable);
let eventCounterDiv = document.getElementById("eventCounterDiv");
if (eventCounterDiv === null) {
const div = document.createElement('div');
div.classList.add('wayfarerrctr_event');
div.id = "eventCounterDiv"
let countLabel = document.createElement('p');
countLabel.textContent = CURRENT_EVENT.label;
const evTable = document.createElement('table');
const evRow = document.createElement('tr');
evTable.appendChild(evRow);
div.appendChild(countLabel);
div.appendChild(evTable);

const counter = document.createElement('td');
counter.classList.add('wayfarerrctr_event_big');
counter.textContent = CURRENT_EVENT.parts.map(p => p.counter).reduce((a, b) => a + b) + '';
counter.style.color = CURRENT_EVENT.color;
evRow.appendChild(counter);
const counter = document.createElement('td');
counter.classList.add('wayfarerrctr_event_big');
counter.textContent = CURRENT_EVENT.parts.map(p => p.counter).reduce((a, b) => a + b) + '';
counter.style.color = CURRENT_EVENT.color;
evRow.appendChild(counter);

if (CURRENT_EVENT.parts.length > 1) {
let evPC;
for (let i = 0; i < CURRENT_EVENT.parts.length; i++) {
if (i % 2 == 0) {
if (evPC) evRow.appendChild(evPC);
evPC = document.createElement('td');
evPC.classList.add('wayfarerrctr_event_ptCell');
if (CURRENT_EVENT.parts.length > 1) {
let evPC;
for (let i = 0; i < CURRENT_EVENT.parts.length; i++) {
if (i % 2 == 0) {
if (evPC) evRow.appendChild(evPC);
evPC = document.createElement('td');
evPC.classList.add('wayfarerrctr_event_ptCell');
}
const evPP = document.createElement('p');
evPP.classList.add('wayfarerrctr_event_ptLabel');
evPP.textContent = CURRENT_EVENT.parts[i].label + ' ';
const evPN = document.createElement('span');
evPN.textContent = CURRENT_EVENT.parts[i].counter + '';
evPN.style.color = now >= CURRENT_EVENT.parts[i].from && now <= CURRENT_EVENT.parts[i].to ? CURRENT_EVENT.color : '#7f7f7f';
evPP.appendChild(evPN);
evPC.appendChild(evPP);
}
const evPP = document.createElement('p');
evPP.classList.add('wayfarerrctr_event_ptLabel');
evPP.textContent = CURRENT_EVENT.parts[i].label + ' ';
const evPN = document.createElement('span');
evPN.textContent = CURRENT_EVENT.parts[i].counter + '';
evPN.style.color = now >= CURRENT_EVENT.parts[i].from && now <= CURRENT_EVENT.parts[i].to ? CURRENT_EVENT.color : '#7f7f7f';
evPP.appendChild(evPN);
evPC.appendChild(evPP);
evRow.appendChild(evPC);
}
evRow.appendChild(evPC);
}

const container = ref.parentNode.parentNode;
container.appendChild(div);
};
const container = ref.parentNode.parentNode;
container.appendChild(div);
}
}
if (!CURRENT_EVENT.initialized) {
CURRENT_EVENT.initialized = true;
if (WFTApi.reviewHistory) {
Expand All @@ -218,6 +327,19 @@
}
}


const awaitElement = get => new Promise((resolve, reject) => {
let triesLeft = 10;
const queryLoop = () => {
const ref = get();
if (ref) resolve(ref);
else if (!triesLeft) reject();
else setTimeout(queryLoop, 100);
triesLeft--;
}
queryLoop();
});

(function() {
const css = `
.wayfarerrctr, .wayfarerrctr_event {
Expand Down
Loading

0 comments on commit c43fe95

Please sign in to comment.