-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathGoogle-Reload-All-&-Current-Tab-Button.user.js
More file actions
67 lines (59 loc) · 2.46 KB
/
Google-Reload-All-&-Current-Tab-Button.user.js
File metadata and controls
67 lines (59 loc) · 2.46 KB
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
// ==UserScript==
// @name Google Reload All & Current Tab Button
// @namespace http://tampermonkey.net/
// @version 0.3
// @description Adds buttons to google.com/* page to reload all tabs and to reload the current tab with detected URL if needed.
// @match https://www.google.com/search?q=*
// @match https://www.google.com/sorry/index?continue=*
// @icon https://www.google.com/s2/favicons?sz=64&domain=google.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Create a Broadcast Channel for communication between tabs
var channel = new BroadcastChannel('googleRedirect');
// Function to create a button
function createButton(text, top, callback) {
const button = document.createElement('button');
button.innerText = text;
button.style.position = "fixed";
button.style.top = top;
button.style.right = "10%";
button.style.padding = "10px";
button.style.zIndex = "1000";
button.style.width = '140px';
button.addEventListener('click', callback);
document.body.appendChild(button);
}
// Create "Reload All Tabs" button
createButton("Reload All Tabs", "16px", function() {
// Send a message through the Broadcast Channel to reload all tabs
channel.postMessage({ command: 'redirect' });
});
// Create "Reload Current Tab" button if a URL is detected
window.addEventListener('load', function() {
// Detect URL on the "unusual traffic" page
const urlRegex = /URL:\s*(https:\/\/\S+)/;
const match = document.body.innerHTML.match(urlRegex);
if (match && match[1]) {
const urlValue = match[1];
// Create "Reload Current Tab" button
createButton("Reload Current Tab", "65px", function() {
// Open the URL in the same tab
window.location.href = urlValue;
});
}
});
// Listen for messages from other tabs to reload if required
channel.onmessage = function(event) {
if (event.data && event.data.command === 'redirect') {
setTimeout(() => {
// Attempt to find the URL from updated page structure
const urlMatch = document.body.innerHTML.match(/URL:\s*(https:\/\/\S+)/);
if (urlMatch && urlMatch[1]) {
window.location.href = urlMatch[1];
}
}, 100);
}
};
})();