-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
129 lines (112 loc) · 4.88 KB
/
background.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
const storageCache = {};
// Asynchronously retrieve data from storage.sync, then cache it.
const initStorageCache = getAllStorageSyncData().then(items => {
// Copy the data retrieved from storage into storageCache.
Object.assign(storageCache, items);
});
chrome.storage.onChanged.addListener((changes, area) => {
if (area === 'sync' && changes.options?.newValue) {
const save = Boolean(changes.options.newValue.save);
const preview = Boolean(changes.options.newValue.preview);
storageCache.options.save = save;
storageCache.options.preview = preview;
}
});
function getAllStorageSyncData() {
// Immediately return a promise and start asynchronous work
return new Promise((resolve, reject) => {
// Asynchronously fetch all data from storage.sync.
chrome.storage.sync.get(null, (items) => {
// Pass any observed errors down the promise chain.
if (chrome.runtime.lastError) {
return reject(chrome.runtime.lastError);
}
// Pass the data retrieved from storage down the promise chain.
resolve(items);
});
});
}
function myfunc(){
if(document.location["href"].endsWith("variables")){
thisinterval = setInterval(function(){
let dashboard=document.querySelector(".gtm-cloak-grey.gtm-cloaked-borderless.gtm-cloaked.gtm-cloaked-spinner.gtm-cloaked-ready");
try{
if(dashboard){
let userDefined = dashboard.firstElementChild.innerText.split(" ");
if(userDefined[0]==="User-Defined"){
clearInterval(thisinterval);
}else{
let ettelement=dashboard.firstElementChild;
let etannetelement = dashboard.lastElementChild;
dashboard.insertBefore(etannetelement,ettelement);
clearInterval(thisinterval);
let usertable=document.querySelector("body > div.gtm-root > div > div.gtm-ng-view > gtm-variable-list > gtm-container-page > div > div > div.gtm-container-page-content-wrapper > div > div > div > div.card.card--table");
let userparent=usertable.parentElement;
let spacer= document.createElement("div");
spacer.className += "card card--table card-bottom-spacer2";
userparent.replaceChild(spacer,usertable);
spacer.appendChild(usertable)
}
}
}catch(TypeError){
}
},500)
}
if(document.location.href.includes("tagmanager.google")){
document.addEventListener('keydown', e => {
if(storageCache?.options?.save){
if (e.ctrlKey && e.key === 's'){
e.preventDefault();
allSaveButtons=document.querySelectorAll("button[type='submit']:not([disabled])");
if(allSaveButtons){
try{
lastSaveButton=allSaveButtons[allSaveButtons.length-1];
lastSaveButton.click();}
catch(e){
}
}
}
}
if(storageCache?.options?.preview){
if(e.ctrlKey && e.key == 'p'){
e.preventDefault();
preview=document.querySelector(".gtm-preview-button:not([disabled])");
if(preview){
try{
preview.click();}
catch(e){
console.warn(e)
}
}
}
}
});}
if(document.location.href.includes("marketingplatform.google")){
document.addEventListener('keydown', e => {
if(storageCache?.options?.save){
if (e.ctrlKey && e.key === 's'){
e.preventDefault();
saveButton=document.querySelector("button[gtmtrigger='users-save-permissions']:not([disabled])");
try{
saveButton.click();}
catch(e){
console.warn(e);
}
}
}
}
);}
}
try{
if(document.location.href.includes("marketingplatform.google" || "tagmanager.google")){
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (changeInfo.status === 'complete') {
chrome.scripting.executeScript({
target: {tabId: tabId},
func: myfunc
});
}
});
}
}catch(e){
}