-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupwork-job-view-history.user.js
55 lines (50 loc) · 1.95 KB
/
upwork-job-view-history.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// ==UserScript==
// @name Upwork Job View History
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.upwork.com/ab/jobs/search/*
// @grant none
// ==/UserScript==
(function() {
const storageKey = 'upwork-history'
const getStorageHistory = () => {
const storageString = localStorage.getItem(storageKey)
if (!storageString) {
return {}
}
let storageObject
try {
storageObject = JSON.parse(storageString)
} catch (e) {
console.error(e)
console.error('Upwork-history: Failed to parse storage JSON')
localStorage.removeItem(storageKey)
storageObject = {}
}
return storageObject
}
const getUpworkJobSections = () => [...document.querySelectorAll('section.job-tile')]
const jobSectionToId = (sectionEl) => sectionEl.querySelector('.job-title-link').href
const markJobSectionViewed = (sectionEl) => sectionEl.style.backgroundColor = '#f5f7ff'
const markJobSectionViewedIfIncluded = (viewedJobIdsFromStorage) => (sectionEl) => {
const jobId = jobSectionToId(sectionEl)
if (!sectionEl.upworkHistoryHandled && viewedJobIdsFromStorage.has(jobId)) markJobSectionViewed(sectionEl)
sectionEl.upworkHistoryHandled = true
return jobId;
}
function runUpworkHistory() {
const storageHistory = getStorageHistory()
const jobSections = getUpworkJobSections()
const viewedJobIdsFromStorage = new Set((storageHistory.viewedJobIds || []))
const onpageJobIds = jobSections.map(markJobSectionViewedIfIncluded(viewedJobIdsFromStorage))
const storageUpdate = {
viewedJobIds: [...(new Set(([...viewedJobIdsFromStorage, ...onpageJobIds])))],
}
localStorage.setItem(storageKey, JSON.stringify(storageUpdate))
}
const scriptIntervalId = setInterval(runUpworkHistory, 1000)
window.__upworkJobViewHistory = {clear: () => {clearInterval(scriptIntervalId); localStorage.removeItem(storageKey); location.reload()}}
runUpworkHistory()
})();