-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoogle_keep.user.js
103 lines (93 loc) · 4.62 KB
/
google_keep.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// ==UserScript==
// @name Google Keep
// @namespace aljgom
// @version 0.11
// @description Additional functionality and UI changes for Google Keep
// @match https://keep.google.com/*
// @author aljgom
// @grant none
// ==/UserScript==
(async function(){
/*** CHANGE TITLE OF TAB **/
var url = document.location.href;
setInterval(()=>{
url = document.location.href;
if(!url.match("#") || url.match(/#(home)/)){
document.title = document.getElementsByClassName('gb_ue gb_pe')[0].innerHTML
return;
}
if(url.match(/#search/)){
document.title = decodeURIComponent(decodeURIComponent(decodeURIComponent(location.hash.substr(1)))).replace('/text','').replace('search=','Search: ') // need to decode it a few consecutive times
return;
}
if(!url.match(/#(NOTE|LIST)/)){ // no note/list selected, use name of menu
document.title = document.getElementsByClassName('gk6SMd')[0].innerText;
return;
}
var titles = document.getElementsByClassName('IZ65Hb-YPqjbf fmcmS-x3Eknd r4nke-YPqjbf')
if(titles.length == 0) titles = document.querySelectorAll('[aria-label=Titel]') // Try it in German
document.title = titles[titles.length-1].innerHTML // Change the tab title to the name of the current List/Note
},2000);
/*** ADD BUTTON FOR SCROLLING TO NEXT UNCHECKED ITEM **/
(async function(){
let nextUnchecked = function*(){ // generator that updates with the next unchecked item
let i = 0;
let unchecked;
while(true){
let currentList = document.querySelectorAll('.VIpgJd-TUo6Hb')[0].querySelectorAll("[aria-checked=false]");
if(!unchecked || unchecked.length != currentList.length -1 ){ // uncheck variable hasnt' been set, or selection length changed
unchecked = Array.from( currentList ) // update unchecked list
unchecked.splice(0,1) // remove first result, it's not the correct match
i = 0;
}
if(unchecked.length == 0)
yield;
else{
yield unchecked[i]
i = (i+1) % unchecked.length
}
}
}
let lastChecked = function(){
let checked = document.querySelectorAll('.VIpgJd-TUo6Hb')[0].querySelectorAll("[aria-checked=true]")
return checked[checked.length-1]
}
let scrollToCheckBox = async function(box){
let container = document.querySelectorAll('.VIpgJd-TUo6Hb .IZ65Hb-s2gQvd')[0];
box.scrollIntoView();
container.scrollTo(0,container.scrollTop - 75)
box.style.background = '#e0e0e0' // flash it's background
await sleep(300)
box.style.background = ''
}
let uncheckedIter;
// Insert button into bottom toolbar
let insertButton = function(){
let container = document.querySelectorAll('.VIpgJd-TUo6Hb .IZ65Hb-s2gQvd')[0];
if(!container || !url.match('#LIST')) return; // no list selected
let toolbar = container.parentElement.querySelectorAll('[role=toolbar]')[0]; // bottom toolbar
if(toolbar.buttonInserted) return; // return if list already has button
toolbar.buttonInserted = true;
if(lastChecked() !== undefined){
scrollToCheckBox(lastChecked()); // scroll to last element checked
}
uncheckedIter = nextUnchecked(); // reset unchecked list (if new list opened)
let button = document.createElement('div')
toolbar.appendChild(button)
Object.assign(button.style,{
userSelect: 'none', // disable text selection
color: '#202124',
paddingTop: '.35em'
});
button.innerHTML = "Next"
button.className = "Q0hgme-LgbsSe" // copy class from sibling
button.id = "next_button"
button.onclick = function scrollToNextUnchecked(){
let next = uncheckedIter.next().value
if(!next) return; // no unchecked boxes
scrollToCheckBox(next);
}
}
setInterval(insertButton,2000) // interval to insert button in new opened lists
})();
})();