-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSkelbiuUpdater.user.js
85 lines (74 loc) · 2.76 KB
/
SkelbiuUpdater.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// ==UserScript==
// @id SkelbiuUpdater
// @name Skelbiu.lt updater
// @namespace http://tampermonkey.net/
// @description skelbiu.lt ads renewer
// @author <[email protected]>
// @domain localhost
// @domain localhost:8000
// @domain skelbiu.lt
// @domain www.skelbiu.lt
// @match http://localhost:8000/play.html
// @match http://localhost:8000/*
// @match https://www.skelbiu.lt/mano-skelbimai/*
// @require https://code.jquery.com/jquery-3.2.1.min.js
// @grant GM_setValue
// @grant GM_getValue
// @grant window.focus
// @downloadURL https://github.com/lexxsoft/tamper-monkey/raw/skelbiu/SkelbiuUpdater.user.js
// @version 42
// @run-at document-end
// @license MIT
// ==/UserScript==
// @updateVersion 3
// @grant none
// @run-at document-start
// @updateURL https://github.com/lexxsoft/tamper-monkey/raw/skelbiu/SkelbiuUpdater.meta.js
(function() {
'use strict';
var movement;
// refresh browser window every so often
var movement = setTimeout(reload, 5*60*1000);
$(document).on('mousemove', function(){
if (movement)
movement = clearTimeout(movement);
movement = setTimeout(reload, 5*60*1000)
});
// gather products
var renewables = [];
$('a.renewedAd, a.renewLink').each(function(idx,element){
// one item per table row
var tr = $(this).parents('tr');
var item = {};
item.title = tr.find('h2').text();
item.views = tr.find('stats-text').eq(0).find('span').text();
item.click = tr.find('stats-text').eq(1).find('span').text();
item.updated = $(this).attr('data-updated');
item.fresh = $(this).css('color') === 'rgb(0, 153, 0)';
item.renewal = this;
console.debug('got link', item);
renewables.push(item);
});
// console.log(hrefs);
// filter only stale links and simulate mouse clicks
renewables.filter(function(item){
return item.fresh === false;
}).forEach(function(item){
console.debug('will be updating', item.title);
triggerMouseEvent(item.renewal, 'mouseover');
triggerMouseEvent(item.renewal, 'mousedown');
triggerMouseEvent(item.renewal, 'mouseup');
triggerMouseEvent(item.renewal, 'click');
});
function triggerMouseEvent(node, eventType)
{
var clickEvent = document.createEvent('MouseEvents');
clickEvent.initEvent(eventType, true, true);
node.dispatchEvent(clickEvent);
}
function reload()
{
console.debug('refreshing');
window.document.location.reload(true);
}
})();