Skip to content

Instantly share code, notes, and snippets.

@dk00
Last active December 26, 2018 13:36
Show Gist options
  • Save dk00/c254c99a9f5e2cccb35db0827e8a32d1 to your computer and use it in GitHub Desktop.
Save dk00/c254c99a9f5e2cccb35db0827e8a32d1 to your computer and use it in GitHub Desktop.
FWS helper
// ==UserScript==
// @name FWS Helper
// @description Overwrites alert()
// @include https://fws.coa.gov.tw/*
// @grant none
// @run-at document-start
// ==/UserScript==
unsafeWindow.alertx = str => {
console.log ("Greasemonkey intercepted alert: ", str)
return true
}
const start = () => {
const h = (type, attrs, ...children) => {
const element = Object.assign(document.createElement(type), attrs)
element.append(...children)
return element
}
const qa = s => Array.from(document.querySelectorAll(s))
const I = {
click: s => qa(s).forEach(it => it.click()),
fill: (s, v) => qa(s).forEach(it => it.value = v)
}
const path = location.pathname.toLowerCase()
if (/feelist/.test(path)) {
I.click('[type="checkbox"]:not(:checked)')
}
const p1 = /桃園市及農會補助/
qa('select').filter(it => p1.test(it.textContent))
.forEach(it => {
const label = it.querySelectorAll(`[value="${it.value}"]`).map(it => it.textContet)[0]
if (label && !p1.test(label)) {
const target = it.querySelectorAll('option').filter(it =>
it.textContent.length > label.length &&
it.textContent.includes(label)
).map(it => it.value)[0]
target.value && (it.value = target.value)
}
})
const date = qa('[name="ROC_AddDate"]').map(it => it.value)[0]
I.fill('[name="ROC_InsureHouseStatusChangeDate"]', date)
}
document.addEventListener('DOMContentLoaded', () => {
try {
start()
} catch(e) {}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment