-
Notifications
You must be signed in to change notification settings - Fork 0
/
Session Change.user.js
63 lines (53 loc) · 1.85 KB
/
Session Change.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
56
57
58
59
60
61
62
63
// ==UserScript==
// @name Session Change
// @namespace https://nawanae.github.io/Leetcode-Session-Browser-Binding/
// @version 1.1
// @namespace https://nawanae.github.io/Leetcode-Session-Browser-Binding/Session Change.user.js
// @updateURL https://nawanae.github.io/Leetcode-Session-Browser-Binding/Session Change.user.js
// @description Change/Select browser session at Leetcode.com/session/
// @author NawaNawa
// @match https://leetcode.com/session/
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// ==/UserScript==
(function() {
'use strict';
var getActiveElement = () => {
for(var a of document.querySelectorAll("span[class*='session-name']"))
if(a.innerText.search("Active")!=-1)
return a;
};
var getActiveTitle = () => {
return getActiveElement().title;
};
var delayLastpage = ()=>{setTimeout(()=>{
history.back();
},200);}
var main = () =>
{
let sessionStorage = localStorage.getItem("session");
if(! sessionStorage || sessionStorage=='undefined' )
{
alert("select a section ");
for(let e of document.querySelectorAll("span[class*='session-name']"))e.addEventListener('click',function(e)
{
localStorage.setItem("session",this.title);
delayLastpage();
});
}
else
{
document.querySelector(`span[title='${localStorage.getItem("session")}']`).click();
delayLastpage();
}
}
var tid = setInterval(()=>{
var sessionE = document.querySelector("span[class*='session-name']");
if(sessionE)
{
clearInterval(tid);
main();
}
},200);
// Your code here...
})();