Skip to content

Instantly share code, notes, and snippets.

@Rplus
Created January 28, 2018 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rplus/6d2834e59e4f05cafa114ee67b75d769 to your computer and use it in GitHub Desktop.
Save Rplus/6d2834e59e4f05cafa114ee67b75d769 to your computer and use it in GitHub Desktop.
wecatch-auto-refresh
window.log = {};
const timeInterval = 5.5; // minute(s)
const filters = {
'/B/': 'iv80+',
'/G/': 'iv90+',
'/W/': 'iv0',
'/R/': 'iv100',
'/349.': '醜醜魚',
};
var checkGoodItems = () => {
var imgSrcs = [...document.querySelectorAll('img.leaflet-marker-icon')].map(i => i.src);
var result = Object.keys(filters).reduce((all, f) => {
all[f] = imgSrcs.filter(src => src.indexOf(f) !== -1);
return all;
}, {});
var noticeStrings = Object.keys(result)
.map(i => result[i].length ? `${filters[i]}: ${result[i].length}` : '')
.filter(Boolean);
if (noticeStrings.length) {
let n = new Notification('', { body: noticeStrings.join('\n') });
n.onshow = setTimeout(() => { n.close()}, 10000);
n.onclick = () => {
window.focus();
n.close();
};
}
window.log[new Date().toString()] = { noticeStrings, result };
};
var refresh = () => {
document.querySelector('#custom-control').click();
setTimeout(checkGoodItems, 5000);
};
var refreshTimer = setInterval(refresh, timeInterval * 60 * 1000);
refresh();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment