Last active
March 21, 2021 07:16
-
-
Save theY4Kman/6e3680fdd5383992aeee5f3f4312dd8d to your computer and use it in GitHub Desktop.
There seems no way to search Hulu from the Chrome omnibox, because it no longer fills the search bar using the `?q=query` param. This script resolves that issue.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Hulu fill search input from query params | |
// @namespace https://y4kstudios.com | |
// @updateUrl https://gist.github.com/theY4Kman/6e3680fdd5383992aeee5f3f4312dd8d/raw/e6d247c5e60d3411408f59faa82cdd833b84dac4/hulu-chrome-omnibox-search-fix.tamper.js | |
// @version 0.1 | |
// @description There seems no way to search Hulu from the Chrome omnibox, because it no longer fills the search bar using the `?q=query` param. This script resolves that issue. | |
// @author You | |
// @match https://www.hulu.com/search?* | |
// @grant none | |
// ==/UserScript== | |
function entrypoint() { | |
function setNativeValue(element, value) { | |
const valueSetter = Object.getOwnPropertyDescriptor(element, 'value').set; | |
const prototype = Object.getPrototypeOf(element); | |
const prototypeValueSetter = Object.getOwnPropertyDescriptor(prototype, 'value').set; | |
if (valueSetter && valueSetter !== prototypeValueSetter) { | |
prototypeValueSetter.call(element, value); | |
} else { | |
valueSetter.call(element, value); | |
} | |
} | |
function triggerUpdate(element) { | |
element.dispatchEvent(new Event('input', { bubbles: true })); | |
} | |
function setReactInputValue(element, value) { | |
setNativeValue(element, value); | |
triggerUpdate(element); | |
} | |
function waitFor(fn, interval) { | |
return new Promise((resolve, reject) => { | |
const timerId = setInterval(() => { | |
const rval = fn(); | |
if (rval) { | |
resolve(rval); | |
clearInterval(timerId); | |
} | |
}); | |
}, 50); | |
} | |
function waitForElement(selector) { | |
return waitFor(() => document.querySelector(selector), 50); | |
} | |
function main() { | |
const params = new URLSearchParams(window.location.search); | |
const query = params.get('q'); | |
if (query) { | |
waitForElement('.cu-search-input').then(searchInput => { | |
waitFor(() => Object.getOwnPropertyDescriptor(searchInput, 'value'), 50).then(() => { | |
setReactInputValue(searchInput, query); | |
}); | |
}) | |
} | |
} | |
main(); | |
} | |
(function() { | |
'use strict'; | |
const script = document.createElement('script'); | |
script.appendChild(document.createTextNode('('+ entrypoint +')();')); | |
(document.body || document.head || document.documentElement).appendChild(script); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment