Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
4,672
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.80 KB | None | 0 0
  1. // ==UserScript==
  2. // @name DH Helper
  3. // @version 1.0
  4. // @description
  5. // @author level
  6. // @match http://*.diamondhunt.co/game.php
  7. // @match https://*.diamondhunt.co/game.php
  8. // @run-at document-idle
  9. // @grant none
  10. // ==/UserScript==
  11. console.log('loaded');
  12. loading();
  13. var Hinterval = setInterval(loading, 100);
  14. function loading() {
  15. if (firstLoadGame === false) {
  16. console.log("trying init");
  17. init();
  18. }
  19. }
  20.  
  21. function init() {
  22. clearInterval(Hinterval);
  23. //---- Create the settings elements ---//
  24. console.log('doing function');
  25. var settings = document.createElement('div');
  26. settings.setAttribute('class', 'Hsettings');
  27. settings.setAttribute('id', 'Hsettings');
  28. //document.getElementById('content').appendChild(main);
  29.  
  30. //header
  31. var header = document.createElement('h1');
  32. header.setAttribute('class', 'container-title');
  33. header.setAttribute('id', 'HsettingsHeader');
  34. header.innerHTML = "DH Helper";
  35.  
  36. //Table
  37. var table = document.createElement('table');
  38. //table.setAttribute('class', 'table-style1');
  39. table.setAttribute('id', 'Htable');
  40. table.setAttribute('width', '40%');
  41. table.style = "margin: auto; border-collapse: collapse; background-color: silver; display: table;";
  42.  
  43. //Table Body
  44. var tableBody = document.createElement('tbody');
  45. tableBody.setAttribute('id', 'HtableBody');
  46. tableBody.style ="display: table-row-group; vertical-align: middle; border-color: inherit; border-collapse: collapse;";
  47.  
  48. //-- Each Table Row --//
  49. //Headers
  50. var trHeader1 = document.createElement('tr');
  51. trHeader1.setAttribute('id', 'HtrHeader1');
  52. trHeader1.setAttribute('background-color', 'grey');
  53. trHeader1.style = "cursor: pointer; display: table-row; vertical-align: inherit; border-color: inherit;";
  54.  
  55. var th1 = document.createElement('th');
  56. th1.innerHTML = "Configuration";
  57. th1.style = "background-color: grey; font-weight: bold; text-align: -internal-center; display: table-cell; vertical-align: inherit; cursor: pointer;";
  58. trHeader1.appendChild(th1);
  59.  
  60. var th2 = document.createElement('th');
  61. th2.innerHTML = "Active";
  62. th2.style = "background-color: grey; font-weight: bold; text-align: -internal-center; display: table-cell; vertical-align: inherit; cursor: pointer;";
  63. trHeader1.appendChild(th2);
  64.  
  65. //Desktop Global
  66. var trHeader2 = document.createElement('tr');
  67. trHeader2.setAttribute('id', 'HtrHeader2');
  68. trHeader2.setAttribute('onClick', 'HtrHeader2Click()');
  69. trHeader2.style = "cursor: pointer; display: table-row; vertical-align: inherit; border-color: inherit;";
  70. trHeader2.addEventListener('click', HtrHeader2Click, false);
  71.  
  72. var td1 = document.createElement('td');
  73. td1.innerHTML = "Desktop Notifications";
  74. td1.style = "background-color: silver; text-align: center; display: table-cell; vertical-align: inherit; cursor: pointer; border: 1px solid black;";
  75. trHeader2.appendChild(td1);
  76.  
  77. var td2 = document.createElement('td');
  78. td2.setAttribute('id', 'Htd2');
  79. td2.style = "background-color: silver; text-align: center; display: table-cell; vertical-align: inherit; cursor: pointer; border: 1px solid black;";
  80. if (localStorage.hdesktop == "true") {
  81. var himageyes1 = document.createElement('img');
  82. himageyes1.setAttribute('src', 'images/icons/check.png');
  83. himageyes1.setAttribute('class', 'image-icon-20');
  84. td2.appendChild(himageyes1);
  85. } else {
  86. var himageno1 = document.createElement('img');
  87. himageno1.setAttribute('src', 'images/icons/x.png');
  88. himageno1.setAttribute('class', 'image-icon-20');
  89. td2.appendChild(himageno1);
  90. }
  91. trHeader2.appendChild(td2);
  92.  
  93. //Woodcutting
  94. var trHeader3 = document.createElement('tr');
  95. trHeader3.setAttribute('id', 'HtrHeader3');
  96. trHeader3.setAttribute('onClick', 'HtrHeader3Click()');
  97. trHeader3.style = "cursor: pointer; display: table-row; vertical-align: inherit; border-color: inherit;";
  98. trHeader3.addEventListener('click', HtrHeader3Click, false);
  99.  
  100. var td3 = document.createElement('td');
  101. td3.innerHTML = "Woodcutting Notifications";
  102. td3.style = "background-color: silver; text-align: center; display: table-cell; vertical-align: inherit; cursor: pointer; border: 1px solid black;";
  103. trHeader3.appendChild(td3);
  104.  
  105. var td4 = document.createElement('td');
  106. td4.setAttribute('id', 'Htd4');
  107. td4.style = "background-color: silver; text-align: center; display: table-cell; vertical-align: inherit; cursor: pointer; border: 1px solid black;";
  108. if (localStorage.hwoodcutting == "true") {
  109. var himageyes2 = document.createElement('img');
  110. himageyes2.setAttribute('src', 'images/icons/check.png');
  111. himageyes2.setAttribute('class', 'image-icon-20');
  112. td4.appendChild(himageyes2);
  113. } else {
  114. var himageno2 = document.createElement('img');
  115. himageno2.setAttribute('src', 'images/icons/x.png');
  116. himageno2.setAttribute('class', 'image-icon-20');
  117. td4.appendChild(himageno2);
  118. }
  119. trHeader3.appendChild(td4);
  120.  
  121. //Farming
  122. var trHeader4 = document.createElement('tr');
  123. trHeader4.setAttribute('id', 'HtrHeader4');
  124. trHeader4.setAttribute('onClick', 'HtrHeader4Click()');
  125. trHeader4.style = "cursor: pointer; display: table-row; vertical-align: inherit; border-color: inherit;";
  126. trHeader4.addEventListener('click', HtrHeader4Click, false);
  127.  
  128. var td5 = document.createElement('td');
  129. td5.innerHTML = "Farming Notifications";
  130. td5.style = "background-color: silver; text-align: center; display: table-cell; vertical-align: inherit; cursor: pointer; border: 1px solid black;";
  131. trHeader4.appendChild(td5);
  132.  
  133. var td6 = document.createElement('td');
  134. td6.setAttribute('id', 'Htd6');
  135. td6.style = "background-color: silver; text-align: center; display: table-cell; vertical-align: inherit; cursor: pointer; border: 1px solid black;";
  136. if (localStorage.hfarming == "true") {
  137. var himageyes3 = document.createElement('img');
  138. himageyes3.setAttribute('src', 'images/icons/check.png');
  139. himageyes3.setAttribute('class', 'image-icon-20');
  140. td6.appendChild(himageyes3);
  141. } else {
  142. var himageno3 = document.createElement('img');
  143. himageno3.setAttribute('src', 'images/icons/x.png');
  144. himageno3.setAttribute('class', 'image-icon-20');
  145. td6.appendChild(himageno3);
  146. }
  147. trHeader4.appendChild(td6);
  148.  
  149. //Combat
  150. var trHeader5 = document.createElement('tr');
  151. trHeader5.setAttribute('id', 'HtrHeader5');
  152. trHeader5.setAttribute('onClick', 'HtrHeader5Click()');
  153. trHeader5.style = "cursor: pointer; display: table-row; vertical-align: inherit; border-color: inherit;";
  154. trHeader5.addEventListener('click', HtrHeader5Click, false);
  155.  
  156. var td7 = document.createElement('td');
  157. td7.innerHTML = "Combat Notifications";
  158. td7.style = "background-color: silver; text-align: center; display: table-cell; vertical-align: inherit; cursor: pointer; border: 1px solid black;";
  159. trHeader5.appendChild(td7);
  160.  
  161. var td8 = document.createElement('td');
  162. td8.setAttribute('id', 'Htd8');
  163. td8.style = "background-color: silver; text-align: center; display: table-cell; vertical-align: inherit; cursor: pointer; border: 1px solid black;";
  164. if (localStorage.hfarming == "true") {
  165. var himageyes4 = document.createElement('img');
  166. himageyes4.setAttribute('src', 'images/icons/check.png');
  167. himageyes4.setAttribute('class', 'image-icon-20');
  168. td8.appendChild(himageyes4);
  169. } else {
  170. var himageno4 = document.createElement('img');
  171. himageno4.setAttribute('src', 'images/icons/x.png');
  172. himageno4.setAttribute('class', 'image-icon-20');
  173. td8.appendChild(himageno4);
  174. }
  175. trHeader5.appendChild(td8);
  176.  
  177. //Adding everything together
  178. tableBody.appendChild(trHeader1);
  179. tableBody.appendChild(trHeader2);
  180. tableBody.appendChild(trHeader3);
  181. tableBody.appendChild(trHeader4);
  182. tableBody.appendChild(trHeader5);
  183. table.appendChild(tableBody);
  184.  
  185. settings.appendChild(header);
  186. settings.appendChild(table);
  187.  
  188. document.getElementById('tab-container-profile').appendChild(settings);
  189. console.log('done function');
  190. }
  191.  
  192. function HtrHeader2Click() {
  193. var tdata = document.getElementById('Htd2');
  194. if (localStorage.hdesktop == "true") {
  195. localStorage.hdesktop = "false";
  196. tdata.removeChild(tdata.firstChild);
  197. var himageno5 = document.createElement('img');
  198. himageno5.setAttribute('src', 'images/icons/x.png');
  199. himageno5.setAttribute('class', 'image-icon-20');
  200. tdata.appendChild(himageno5);
  201. } else {
  202. localStorage.hdesktop = "true";
  203. tdata.removeChild(tdata.firstChild);
  204. var himageyes5 = document.createElement('img');
  205. himageyes5.setAttribute('src', 'images/icons/check.png');
  206. himageyes5.setAttribute('class', 'image-icon-20');
  207. tdata.appendChild(himageyes5);
  208. Notification.requestPermission();
  209. }
  210. }
  211. function HtrHeader3Click() {
  212. var tdata = document.getElementById('Htd4');
  213. if (localStorage.hwoodcutting == "true") {
  214. localStorage.hwoodcutting = "false";
  215. tdata.removeChild(tdata.firstChild);
  216. var himageno6 = document.createElement('img');
  217. himageno6.setAttribute('src', 'images/icons/x.png');
  218. himageno6.setAttribute('class', 'image-icon-20');
  219. tdata.appendChild(himageno6);
  220. } else {
  221. localStorage.hwoodcutting = "true";
  222. tdata.removeChild(tdata.firstChild);
  223. var himageyes6 = document.createElement('img');
  224. himageyes6.setAttribute('src', 'images/icons/check.png');
  225. himageyes6.setAttribute('class', 'image-icon-20');
  226. tdata.appendChild(himageyes6);
  227. }
  228. }
  229. function HtrHeader4Click() {
  230. var tdata = document.getElementById('Htd6');
  231. if (localStorage.hfarming == "true") {
  232. localStorage.hfarming = "false";
  233. tdata.removeChild(tdata.firstChild);
  234. var himageno7 = document.createElement('img');
  235. himageno7.setAttribute('src', 'images/icons/x.png');
  236. himageno7.setAttribute('class', 'image-icon-20');
  237. tdata.appendChild(himageno7);
  238. } else {
  239. localStorage.hfarming = "true";
  240. tdata.removeChild(tdata.firstChild);
  241. var himageyes7 = document.createElement('img');
  242. himageyes7.setAttribute('src', 'images/icons/check.png');
  243. himageyes7.setAttribute('class', 'image-icon-20');
  244. tdata.appendChild(himageyes7);
  245. }
  246. }
  247. function HtrHeader5Click() {
  248. var tdata = document.getElementById('Htd8');
  249. if (localStorage.hcombat == "true") {
  250. localStorage.hcombat = "false";
  251. tdata.removeChild(tdata.firstChild);
  252. var himageno8 = document.createElement('img');
  253. himageno8.setAttribute('src', 'images/icons/x.png');
  254. himageno8.setAttribute('class', 'image-icon-20');
  255. tdata.appendChild(himageno8);
  256. } else {
  257. localStorage.hcombat = "true";
  258. tdata.removeChild(tdata.firstChild);
  259. var himageyes8 = document.createElement('img');
  260. himageyes8.setAttribute('src', 'images/icons/check.png');
  261. himageyes8.setAttribute('class', 'image-icon-20');
  262. tdata.appendChild(himageyes8);
  263. }
  264. }
  265. //---- Create observers for each notification ----//
  266. //Woodcutting
  267. var woodobserver = new MutationObserver(function(mutations) {
  268. mutations.forEach(function(mutationRecord) {
  269. if (document.getElementById("notification-static-woodcutting").getAttribute("display") != "none") {
  270. if ((localStorage.hdesktop == "true") && (localStorage.hwoodcutting == "true")) {
  271. var notification = new Notification("Woodcutting",{ icon: 'images/icons/woodcutting.png' });
  272. }
  273. }
  274. });
  275. });
  276.  
  277. var target1 = document.getElementById('notification-static-woodcutting');
  278. woodobserver.observe(target1, { attributes : true, attributeFilter : ['style'] });
  279.  
  280. //Farming
  281. var farmingobserver = new MutationObserver(function(mutations) {
  282. mutations.forEach(function(mutationRecord) {
  283. if (document.getElementById("notification-static-farming").getAttribute("display") != "none") {
  284. if ((localStorage.hdesktop == "true") && (localStorage.hfarming == "true")) {
  285. var notification = new Notification("Farming",{ icon: 'images/icons/watering-can.png' });
  286. }
  287. }
  288. });
  289. });
  290.  
  291. var target2 = document.getElementById('notification-static-farming');
  292. farmingobserver.observe(target2, { attributes : true, attributeFilter : ['style'] });
  293.  
  294. //Combat
  295. var combatobserver = new MutationObserver(function(mutations) {
  296. mutations.forEach(function(mutationRecord) {
  297. if (document.getElementById("notification-static-combat").getAttribute("display") != "none") {
  298. if ((localStorage.hdesktop == "true") && (localStorage.hcombat == "true")) {
  299. var notification = new Notification("Combat",{ icon: 'images/icons/combat.png' });
  300. }
  301. }
  302. });
  303. });
  304.  
  305. var target3 = document.getElementById('notification-static-combat');
  306. combatobserver.observe(target3, { attributes : true, attributeFilter : ['style'] });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement