-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtamperscript.js
36 lines (34 loc) · 1.28 KB
/
tamperscript.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
// ==UserScript==
// @name YouTube Search Bar Forwarding Handler
// @version 1.0
// @description Listens for middle-mouse - open new window - request in youtube's search bar, then opens search request as blank_
// @author AquaJo
// @match https://www.youtube.com/*
// @grant none
// ==/UserScript==
(function () {
"use strict";
// Event listener for pointer down
document.addEventListener("pointerdown", function (event) {
// Check if the middle mouse button is clicked
if (event.button === 1) {
// Check if the clicked target matches the desired div class
const target = event.target.closest(
"div.ytSuggestionComponentSuggestion"
);
if (target) {
event.preventDefault(); // Prevent default behavior
// Get query param text and convert to URI format
const topic = target
.querySelector(".ytSuggestionComponentLeftContainer")
.querySelector(".ytSuggestionComponentBold").parentElement.innerText;
const topicURI = encodeURIComponent(topic);
// Open the desired link in a new tab (convertion to + etc seemingly not needed)
window.open(
"https://www.youtube.com/results?search_query=" + topicURI,
"_blank"
);
}
}
});
})();