Skip to content

Instantly share code, notes, and snippets.

@jlennox
Created April 20, 2022 22:59
Show Gist options
  • Save jlennox/bff29151d76b38673d54b34ab50bbec0 to your computer and use it in GitHub Desktop.
Save jlennox/bff29151d76b38673d54b34ab50bbec0 to your computer and use it in GitHub Desktop.
Add seach to Hulu's url using tampermonkey
// ==UserScript==
// @name Add URL search to hulu
// @namespace http://tampermonkey.net/
// @version 0.1
// @match https://www.hulu.com/search?q=*
// @grant none
// ==/UserScript==
function performSearch()
{
const params = new URLSearchParams(location.search);
const term = params.get("q");
if (!term) return;
const input = document.querySelector("input[aria-label=Search]");
if (!input) {
console.error("Failed to find input.");
return;
}
// The timeout is needed because it appears the event is not immediately bound.
setTimeout(() => {
// Thanks to https://stackoverflow.com/questions/23892547/what-is-the-best-way-to-trigger-onchange-event-in-react-js
const setter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value").set;
setter.call(input, term);
input.dispatchEvent(new InputEvent('input', {
'bubbles': true,
'cancelable': true
}));
}, 1000);
}
if (document.body && document.readyState != "loading") {
performSearch();
} else {
document.addEventListener("DOMContentLoaded", () => performSearch());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment