-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImperiaAlarm.user.js
More file actions
executable file
·89 lines (78 loc) · 3.06 KB
/
ImperiaAlarm.user.js
File metadata and controls
executable file
·89 lines (78 loc) · 3.06 KB
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
86
87
88
89
// ==UserScript==
// @name ImperiaAlarm
// @namespace https://imperiaonline.org
// @include https://imperiaonline.org/*
// @icon https://ihcdn3.ioimg.org/iov6live/gui/favicon.png
// @author argorar
// @match *.imperiaonline.org/imperia/game_v6/game/village.php
// @match *.gameofemperors.com/imperia/game_v6/game/village.php
// @require https://raw.githubusercontent.com/Nickersoft/push.js/master/bin/push.min.js
// @grant none
// @updateURL https://github.com/argorar/Imperia-Scripts/raw/master/ImperiaAlarm.user.js
// @downloadURL https://github.com/argorar/Imperia-Scripts/raw/master/ImperiaAlarm.user.js
// @version 1.4.0
// ==/UserScript==
(function() {
"use strict";
setInterval("location.reload()", 600000);
function addJQuery(callback) {
var script = document.createElement("script");
script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js");
script.addEventListener("load", function() {
var script = document.createElement("script");
script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();";
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}
function sonido() {
let sound = document.createElement("object");
sound.setAttribute("width", "5px");
sound.setAttribute("height", "5px");
sound.setAttribute("data", "https://freesound.org/data/previews/254/254819_4597795-lq.mp3");
document.body.appendChild(sound);
}
function underAttack() {
let personales = document.getElementsByClassName("ui-icon attack-me")[0];
let alianza = document.getElementsByClassName("ui-icon attack-alliance")[0];
return personales != null || alianza != null;
}
//false: primera vez , true: no es la primera vez
var underAttackFlag = false;
function firstAttack() {
document.location.href = "javascript:void(xajax_viewMissions(container.open({saveName:'missions', title:'Mis misiones'}), {tab:'incoming'}))"; //abre las misiones
let tdElem = document.getElementsByClassName("numeral tooltip-arrow ui-pass"); //lista de ataques
for (let i = 0; i < tdElem.length; i++) {
let tdText = tdElem[i].innerText; //número del ejercito
if (tdText.length > 3) { //ataque mayor a 999 soldados
underAttackFlag = true;
sonido();
break;
}
}
}
setInterval(
function checker() {
if (underAttack()) {
if (underAttackFlag === false) {
firstAttack();
} else {
sonido();
}
} else { //No hay ataques
underAttackFlag = false; //se reinicia el estado
}
}, 5000);
function notification(title, msg) {
Push.create(title, {
body: msg,
icon: "https://ihcdn3.ioimg.org/iov6live/gui/favicon.png",
timeout: 4000,
onClick: function() {
window.focus();
this.close();
}
});
}
notification("Información", "Alarma activada correctamente.");
})();