Skip to content

Instantly share code, notes, and snippets.

@alankyshum
Last active October 30, 2020 20:35
Show Gist options
  • Save alankyshum/43ffd75e7f911fe2ac6f698ad97fd57f to your computer and use it in GitHub Desktop.
Save alankyshum/43ffd75e7f911fe2ac6f698ad97fd57f to your computer and use it in GitHub Desktop.
TamperMonkey Scripts
/**
* 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);
})();
@BloonstoDoB
Copy link

bruh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment