Last active
October 30, 2020 20:35
-
-
Save alankyshum/43ffd75e7f911fe2ac6f698ad97fd57f to your computer and use it in GitHub Desktop.
TamperMonkey Scripts
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
/** | |
* 1. Install TamperMonkey | |
* 2. Configure a custom search engine in Chromium-based browser | |
* - https://humanum.arts.cuhk.edu.hk/Lexis/lexi-can/?q=%s | |
* 3. Save this script in TamperMonkey | |
* 4. When you load the page with https://humanum.arts.cuhk.edu.hk/Lexis/lexi-can/?q=機 | |
* 5. The script will loop every second (until 10 sec) to check for the submission form | |
* 6. When the form is ready, it will submit the form with the word `機` | |
* 7. Then you will see the cantonese pronounciation from CUHK | |
*/ | |
// ==UserScript== | |
// @name CantoneseSearcher | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Automatically redirect chinese word to CUTK cantonese search | |
// @author alankyshum | |
// @match https://humanum.arts.cuhk.edu.hk/Lexis/lexi-can/?q=* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const searchWord = (new URL(location.href)).searchParams.get('q'); | |
console.log(`TamperMonkey: Showing cantonese for ${searchWord}`); | |
const waitInterval = 1000; | |
let waitTimeout = 10000; | |
const waitForSearchForm = setInterval(() => { | |
waitTimeout -= waitInterval; | |
if (waitTimeout <= 0) { | |
clearInterval(waitForSearchForm); | |
} | |
const searchForm = window.frames.left.document.forms[0]; | |
if (!searchForm) return; | |
const searchInput = searchForm.querySelector('input[name="q"]'); | |
searchInput.value = searchWord; | |
searchForm.submit(); | |
clearInterval(waitForSearchForm); | |
}, waitInterval); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bruh