Advertisement
Guest User

Untitled

a guest
Jan 13th, 2016
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 50.59 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Neptun PowerUp!
  3. // @namespace http://example.org
  4. // @description Felturbózza a Neptun-odat
  5. // @version 1.49.5
  6. // @include https://*neptun*/*hallgato*/*
  7. // @include https://*hallgato*.*neptun*/*
  8. // @include https://netw*.nnet.sze.hu/hallgato/*
  9. // @include https://nappw.dfad.duf.hu/hallgato/*
  10. // @include https://host.sdakft.hu/*
  11. // @include https://neptun.ejf.hu/ejfhw/*
  12. // @grant GM_xmlhttpRequest
  13. // @grant GM_getValue
  14. // @grant GM_setValue
  15. // @grant GM_info
  16. // @require https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js
  17. // ==/UserScript==
  18.  
  19. var npu = {
  20.  
  21. /* == STARTUP == */
  22.  
  23. /* Run features */
  24. init: function() {
  25. if(!this.isNeptunPage()) {
  26. return;
  27. }
  28.  
  29. this.initParameters();
  30. this.initStorage();
  31.  
  32. if(this.isLogin()) {
  33. this.initUserSelect();
  34. this.initAutoLogin();
  35. this.fixWaitDialog();
  36. }
  37. else {
  38. this.hideHeader();
  39. this.fixTitle();
  40. this.fixMenu();
  41. this.fixTermSelect();
  42. this.fixPagination();
  43. this.initKeepSession();
  44. this.initProgressIndicator();
  45.  
  46. if(this.isPage("0203") || this.isPage("c_common_timetable")) {
  47. this.fixTimetable();
  48. }
  49.  
  50. if(this.isPage("0206") || this.isPage("h_markbook")) {
  51. this.fixMarkList();
  52. }
  53.  
  54. if(this.isPage("0222") || this.isPage("h_advance")) {
  55. this.fixProgressList();
  56. }
  57.  
  58. if(this.isPage("0303") || this.isPage("h_addsubjects")) {
  59. this.fixCourseList();
  60. this.initCourseAutoList();
  61. this.initCourseStore();
  62. }
  63.  
  64. if(this.isPage("0401") || this.isPage("h_exams")) {
  65. this.fixExamList();
  66. this.initExamAutoList();
  67. }
  68.  
  69. this.initStat();
  70. }
  71. },
  72.  
  73. /* == USER DATA == */
  74.  
  75. /* Stored data */
  76. data: { },
  77.  
  78. /* Initialize the storage module */
  79. initStorage: function() {
  80. npu.loadData();
  81. },
  82.  
  83. /* Load all data from local storage */
  84. loadData: function() {
  85. try {
  86. npu.data = JSON.parse(GM_getValue("data")) || {};
  87. }
  88. catch(e) { }
  89. npu.upgradeSchema();
  90. },
  91.  
  92. /* Save all data to local storage */
  93. saveData: function() {
  94. this.runAsync(function() {
  95. GM_setValue("data", JSON.stringify(npu.data));
  96. });
  97. },
  98.  
  99. /* Gets the specified property or all data of the specified user or the current user */
  100. getUserData: function(domain, user, key) {
  101. domain = domain ? domain : npu.domain;
  102. user = user ? user : npu.user;
  103. key = Array.prototype.slice.call(arguments).slice(2);
  104. key = key.length == 1 && typeof key[0].length != "undefined" ? key[0] : key;
  105. return npu.getChild(npu.data, ["users", domain, user, "data"].concat(key));
  106. },
  107.  
  108. /* Sets the specified property of the specified user or the current user */
  109. setUserData: function(domain, user, key, value) {
  110. domain = domain ? domain : npu.domain;
  111. user = user ? user : npu.user;
  112. key = Array.prototype.slice.call(arguments).slice(2, arguments.length - 1);
  113. key = key.length == 1 && typeof key[0].length != "undefined" ? key[0] : key;
  114. value = arguments.length > 4 ? arguments[arguments.length - 1] : value;
  115. npu.setChild(npu.data, ["users", domain, user, "data"].concat(key), value);
  116. },
  117.  
  118. /* Upgrade the data schema to the latest version */
  119. upgradeSchema: function() {
  120. var ver = typeof npu.data.version != "undefined" ? npu.data.version : 0;
  121.  
  122. /* < 1.3 */
  123. if(ver < 1) {
  124. try {
  125. var users = JSON.parse(GM_getValue("neptun.users"));
  126. }
  127. catch(e) { }
  128. if(users != null && typeof users.length != "undefined") {
  129. for(var i = 0; i < users.length; i++) {
  130. npu.setChild(npu.data, ["users", npu.domain, users[i][0].toUpperCase(), "password"], npu.encodeBase64(users[i][1]));
  131. }
  132. }
  133. try {
  134. var courses = JSON.parse(GM_getValue("neptun.courses"));
  135. }
  136. catch(e) { }
  137. if(typeof courses == "object") {
  138. for(var user in courses) {
  139. for(var subject in courses[user]) {
  140. npu.setUserData(null, user, ["courses", "_legacy", subject], courses[user][subject]);
  141. }
  142. }
  143. }
  144. npu.data.version = 1;
  145. }
  146.  
  147. npu.saveData();
  148. },
  149.  
  150. /* == LOGIN == */
  151.  
  152. /* Returns users with stored credentials */
  153. getLoginUsers: function() {
  154. var users = [], list = npu.getChild(npu.data, ["users", npu.domain]);
  155. for(var user in list) {
  156. if(typeof list[user].password == "string" && list[user].password != "") {
  157. users.push(user);
  158. }
  159. }
  160. return users;
  161. },
  162.  
  163. /* Load and display user select field */
  164. initUserSelect: function() {
  165. var users = npu.getLoginUsers();
  166.  
  167. $(".login_left_side .login_input").css("text-align", "left");
  168.  
  169. var selectField = $('<select id="user_sel" class="bevitelimezo" name="user_sel"></select>').hide();
  170. for(var i = 0; i < users.length; i++) {
  171. selectField.append('<option id="' + users[i] + '" value="' + users[i] + '" class="neptun_kod">' + users[i] + '</option>');
  172. }
  173.  
  174. selectField.append('<option disabled="disabled" class="user_separator">&nbsp;</option>');
  175.  
  176. selectField.append('<option id="other_user" value="__OTHER__">Más felhasználó...</option>');
  177. selectField.append('<option id="edit_list" value="__DELETE__">Tárolt kód törlése...</option>');
  178.  
  179. $("td", selectField).css("position", "relative");
  180. selectField.css("font-weight", "bold").css("font-family", "consolas, courier new, courier, monospace").css("font-size", "1.5em");
  181. $("option[class!=neptun_kod]", selectField).css("font-size", "0.8em").css("font-family", "tahoma").css("font-weight", "normal").css("color", "#666").css("font-style", "italic");
  182. $("option.user_separator", selectField).css("font-size", "0.5em");
  183.  
  184. selectField.bind("mousedown focus change", function() { npu.abortLogin() });
  185. $("#pwd, #Submit, #btnSubmit").bind("mousedown focus change", function() { npu.abortLogin() });
  186.  
  187. selectField.bind("change", function() {
  188. npu.clearLogin();
  189.  
  190. if($(this).val() == "__OTHER__") {
  191. npu.hideSelect();
  192. return false;
  193. }
  194.  
  195. if($(this).val() == "__DELETE__") {
  196. $("#user_sel").val(users[0]).trigger("change");
  197. var defaultString = "mindegyiket";
  198. for(var i = 0; i < users.length; i++) {
  199. defaultString += " / " + users[i];
  200. }
  201. itemToDelete = unsafeWindow.prompt("Írd be a törlendő neptun kódot. Az összes törléséhez írd be: MINDEGYIKET", defaultString);
  202. if(itemToDelete == "" || itemToDelete == null) {
  203. return false;
  204. }
  205.  
  206. var deleted = false;
  207. for(var i = 0; i < users.length; i++) {
  208. if(users[i] == itemToDelete.toUpperCase() || itemToDelete.toUpperCase() == "MINDEGYIKET") {
  209. npu.setChild(npu.data, ["users", npu.domain, users[i], "password"], null);
  210. deleted = true;
  211. }
  212. }
  213.  
  214. if(!deleted) {
  215. if(confirm("A megadott neptun kód nincs benne a tárolt listában. Megpróbálod újra?")) {
  216. $("#user_sel").val("__DELETE__").trigger("change");
  217. }
  218. return false;
  219. }
  220.  
  221. npu.saveData();
  222.  
  223. if(itemToDelete.toUpperCase() == "MINDEGYIKET") {
  224. alert("Az összes tárolt neptun kód törölve lett a bejelentkezési listából.");
  225. window.location.reload();
  226. return false;
  227. }
  228.  
  229. alert("A(z) " + itemToDelete + " felhasználó törölve lett a bejelentkezési listából.");
  230. window.location.reload();
  231. return false;
  232. }
  233.  
  234. $("#user").val(users[$(this).get(0).selectedIndex]);
  235. $("#pwd").val(npu.decodeBase64(npu.getChild(npu.data, ["users", npu.domain, users[$(this).get(0).selectedIndex], "password"])));
  236. });
  237.  
  238. $("input[type=button].login_button").attr("onclick", "").bind("click", function(e) {
  239. e.preventDefault();
  240.  
  241. if($("#user_sel").val() == "__OTHER__") {
  242. if($("#user").val().trim() == "" || $("#pwd").val().trim() == "") {
  243. return;
  244. }
  245.  
  246. var foundID = -1;
  247. for(var i = 0; i < users.length; i++) {
  248. if(users[i] == $("#user").val().toUpperCase()) {
  249. foundID = i;
  250. }
  251. }
  252.  
  253. if(foundID == -1) {
  254. if(confirm("Szeretnéd menteni a beírt adatokat, hogy később egy kattintással be tudj lépni erről a számítógépről?")) {
  255. npu.setChild(npu.data, ["users", npu.domain, $("#user").val().toUpperCase(), "password"], npu.encodeBase64($("#pwd").val()));
  256. npu.saveData();
  257. }
  258. npu.submitLogin();
  259. return;
  260. }
  261. else {
  262. $("#user_sel").val(users[foundID]);
  263. }
  264. }
  265.  
  266. if($("#user_sel").val() == "__DELETE__") {
  267. return;
  268. }
  269.  
  270. if($("#pwd").val() != npu.decodeBase64(npu.getChild(npu.data, ["users", npu.domain, users[$("#user_sel").get(0).selectedIndex], "password"]))) {
  271. if(confirm("Szeretnéd megváltoztatni a(z) " + $("#user").val().toUpperCase() + " felhasználó tárolt jelszavát a most beírt jelszóra?")) {
  272. npu.setChild(npu.data, ["users", npu.domain, users[$("#user_sel").get(0).selectedIndex], "password"], npu.encodeBase64($("#pwd").val()));
  273. npu.saveData();
  274. }
  275. }
  276.  
  277. npu.submitLogin();
  278. return;
  279. });
  280.  
  281. $("#user").parent().append(selectField);
  282. npu.showSelect();
  283. selectField.trigger("change");
  284. },
  285.  
  286. /* Initialize auto login and start countdown */
  287. initAutoLogin: function() {
  288. var users = npu.getLoginUsers();
  289.  
  290. if(users.length < 1) {
  291. return;
  292. }
  293.  
  294. var submit = $("#Submit, #btnSubmit");
  295.  
  296. npu.loginCount = 3;
  297. npu.loginButton = submit.attr("value");
  298. submit.attr("value", npu.loginButton + " (" + npu.loginCount + ")");
  299.  
  300. $(".login_button_td").append('<div id="abortLogin" style="text-align: center; margin: 23px 0 0 128px"><a href="#" class="abort_login">Megszakít</a></div>');
  301. $(".login_button_td a.abort_login").click(function(e) {
  302. e.preventDefault();
  303. npu.abortLogin();
  304. });
  305.  
  306. npu.loginTimer = window.setInterval(function() {
  307. npu.loginCount--;
  308. submit.attr("value", npu.loginButton + " (" + npu.loginCount + ")");
  309.  
  310. if(npu.loginCount <= 0) {
  311. npu.submitLogin();
  312. npu.abortLogin();
  313. submit.attr("value", npu.loginButton + "...");
  314. }
  315. }, 1000);
  316. },
  317.  
  318. /* Abort the auto login countdown */
  319. abortLogin: function() {
  320. window.clearInterval(npu.loginTimer);
  321. $("#Submit, #btnSubmit").attr("value", npu.loginButton);
  322. $("#abortLogin").remove();
  323. },
  324.  
  325. /* Clears the login form */
  326. clearLogin: function() {
  327. $("#user").val("");
  328. $("#pwd").val("");
  329. },
  330.  
  331. /* Display user select field */
  332. showSelect: function() {
  333. $("#user").hide();
  334. $("#user_sel").show().focus();
  335. npu.runEval(' Page_Validators[0].controltovalidate = "user_sel" ');
  336. },
  337.  
  338. /* Hide user select field and display original textbox */
  339. hideSelect: function() {
  340. $("#user_sel").hide();
  341. $("#user").show().focus();
  342. npu.runEval(' Page_Validators[0].controltovalidate = "user" ');
  343. },
  344.  
  345. /* Submit the login form */
  346. submitLogin: function() {
  347. unsafeWindow.docheck();
  348. },
  349.  
  350. /* Reconfigure server full wait dialog parameters */
  351. fixWaitDialog: function() {
  352. unsafeWindow.maxtrynumber = 1e6;
  353. /* Export the patched starttimer function into the security context of the page in order to avoid an "access denied" error on Firefox. Details: https://blog.mozilla.org/addons/2014/04/10/changes-to-unsafewindow-for-the-add-on-sdk */
  354. var timerFunction = function() {
  355. unsafeWindow.login_wait_timer = unsafeWindow.setInterval(unsafeWindow.docheck, 5000);
  356. };
  357. exportFunction(timerFunction, unsafeWindow, {defineAs: "npu_starttimer"});
  358. unsafeWindow.starttimer = unsafeWindow.npu_starttimer;
  359. },
  360.  
  361. /* == MAIN == */
  362.  
  363. /* Hide page header to save vertical space */
  364. hideHeader: function() {
  365. $("#panHeader, #panCloseHeader").hide();
  366. $("table.top_menu_wrapper").css("margin-top", "5px").css("margin-bottom", "8px");
  367. $("#form1 > fieldset").css("border", "0 none");
  368. },
  369.  
  370. /* Add current page name to the window title */
  371. fixTitle: function() {
  372. var originalTitle = document.title;
  373. window.setInterval(function() {
  374. var pageTitle = $("#menucaption").text().toString();
  375. document.title = (pageTitle == "" ? "" : pageTitle + " - ") + originalTitle;
  376. }, 1000);
  377. },
  378.  
  379. /* Fix opening in new tab and add shortcuts */
  380. fixMenu: function() {
  381. var color = $("#lbtnQuit").css("color");
  382.  
  383. $(
  384. '<style type="text/css"> ' +
  385. 'ul.menubar, ' +
  386. '.top_menu_wrapper ' +
  387. '{ ' +
  388. 'cursor: default !important; ' +
  389. '} ' +
  390. '#mb1 li.menu-parent ' +
  391. '{ ' +
  392. 'color: #525659 !important; ' +
  393. '} ' +
  394. '#mb1 li.menu-parent.has-target ' +
  395. '{ ' +
  396. 'color: ' + color + ' !important; ' +
  397. '} ' +
  398. '#mb1 li.menu-parent.has-target:hover ' +
  399. '{ ' +
  400. 'color: #000 !important; ' +
  401. '} ' +
  402. '</style>'
  403. ).appendTo("head");
  404.  
  405. $("#mb1_Tanulmanyok").attr("targeturl", "main.aspx?ctrl=0206&ismenuclick=true").attr("hoverid", "#mb1_Tanulmanyok_Leckekonyv");
  406. $("#mb1_Targyak").attr("targeturl", "main.aspx?ctrl=0303&ismenuclick=true").attr("hoverid", "#mb1_Targyak_Targyfelvetel");
  407. $("#mb1_Vizsgak").attr("targeturl", "main.aspx?ctrl=0401&ismenuclick=true").attr("hoverid", "#mb1_Vizsgak_Vizsgajelentkezes");
  408.  
  409. var orarend = $('<li aria-haspopup="false" tabindex="0" role="menuitem" class="menu-parent has-target" id="mb1_Orarend" targeturl="main.aspx?ctrl=0203&amp;ismenuclick=true">Órarend</li>');
  410. $("#mb1_Targyak").before(orarend);
  411. $("#mb1_Tanulmanyok_Órarend").remove();
  412.  
  413. if(!$("#upChooser_chooser_kollab").hasClass("KollabChooserSelected")) {
  414. $('<li aria-haspopup="false" tabindex="0" role="menuitem" class="menu-parent has-target" id="mb1_MeetStreet" targeturl="javascript:__doPostBack(\'upChooser$btnKollab\',\'\')">Meet Street</li>').appendTo("#mb1");
  415. }
  416. if(!$("#upChooser_chooser_neptun").hasClass("NeptunChooserSelected")) {
  417. $('<li aria-haspopup="false" tabindex="0" role="menuitem" class="menu-parent has-target" id="mb1_TanulmanyiRendszer" targeturl="javascript:__doPostBack(\'upChooser$btnNeptun\',\'\')">Neptun</li>').appendTo("#mb1");
  418. }
  419.  
  420. $("#mb1 li[targeturl]").css("position", "relative").each(function() {
  421. $(this).addClass("has-target");
  422. var a = $('<a href="' + $(this).attr("targeturl") + '" style="display: block; position: absolute; left: 0; top: 0; width: 100%; height: 100%"></a>');
  423. a.click(function(e) {
  424. $("ul.menu").css("visibility", "hidden");
  425. e.stopPropagation();
  426. });
  427. var hoverid = $(this).attr("hoverid");
  428. if(hoverid) {
  429. a.hover(function() { $(hoverid).addClass("menu-hover"); }, function() { $(hoverid).removeClass("menu-hover"); });
  430. }
  431. $(this).append(a);
  432. });
  433. },
  434.  
  435. /* Replace term drop-down list with buttons */
  436. fixTermSelect: function() {
  437. $(
  438. '<style type="text/css"> ' +
  439. '.termSelect ' +
  440. '{ ' +
  441. 'list-style: none; ' +
  442. 'padding: 0; ' +
  443. '} ' +
  444. '.termSelect li ' +
  445. '{ ' +
  446. 'display: inline-block; ' +
  447. '*display: inline; ' +
  448. 'vertical-align: middle; ' +
  449. 'margin: 0 15px 0 0; ' +
  450. 'line-height: 250%; ' +
  451. '} ' +
  452. '.termSelect li a ' +
  453. '{ ' +
  454. 'padding: 5px; ' +
  455. '} ' +
  456. '.termSelect li a.button ' +
  457. '{ ' +
  458. 'color: #FFF; ' +
  459. 'box-shadow: none; ' +
  460. 'text-decoration: none; ' +
  461. 'cursor: default; ' +
  462. '} ' +
  463. '</style>'
  464. ).appendTo("head");
  465.  
  466. var findTermSelect = function() {
  467. return $("#upFilter_cmbTerms, #upFilter_cmb_m_cmb, #cmbTermsNormal, #upFilter_cmbTerms_m_cmb, #cmb_cmb, #c_common_timetable_cmbTermsNormal, #cmbTerms_cmb").first();
  468. };
  469. var clickExecuteButton = function() {
  470. if(["0303", "h_addsubjects", "0401", "h_exams", "0503", "h_transactionlist"].indexOf(npu.getPage()) != -1) {
  471. return;
  472. }
  473. npu.runEval(function() {
  474. $("#upFilter_expandedsearchbutton").click();
  475. });
  476. };
  477. var selectTerm = function(term) {
  478. var termSelect = findTermSelect(), el = $(".termSelect a[data-value=" + term + "]");
  479. if(el.size() == 0 || el.hasClass("button")) {
  480. return false;
  481. }
  482. termSelect.val(el.attr("data-value"));
  483. $(".termSelect .button").removeClass("button");
  484. el.addClass("button");
  485. var onChange = termSelect[0].getAttributeNode("onchange");
  486. if(onChange) {
  487. npu.runAsync(function() { npu.runEval(onChange.value); });
  488. }
  489. return true;
  490. };
  491.  
  492. window.setInterval(function() {
  493. var termSelect = findTermSelect();
  494. if(termSelect.is(":disabled")) {
  495. return;
  496. }
  497. if(termSelect.is(":visible")) {
  498. $(".termSelect").remove();
  499. var select = $('<ul class="termSelect"></ul>');
  500. var stored = npu.getUserData(null, null, ["termSelect", npu.getPage()]);
  501. var found = false;
  502. $("option", termSelect).each(function() {
  503. if($(this).attr("value") == "-1") { return; }
  504. var item = $('<li><a href="#" data-value="' + $(this).attr("value") + '" class="' + (termSelect.val() == $(this).attr("value") ? "button" : "") + '">' + $(this).html() + "</a></li>");
  505. if(typeof stored != "undefined" && $(this).attr("value") == stored) {
  506. found = true;
  507. }
  508. $("a", item).bind("click", function(e) {
  509. e.preventDefault();
  510. var term = $(this).attr("data-value");
  511. if(selectTerm(term)) {
  512. if(stored != term) {
  513. stored = term;
  514. npu.setUserData(null, null, ["termSelect", npu.getPage()], term);
  515. npu.saveData();
  516. }
  517. clickExecuteButton();
  518. }
  519. });
  520. select.append(item);
  521. });
  522. termSelect.parent().append(select);
  523. termSelect.hide();
  524. if(!termSelect.data("initialized")) {
  525. termSelect.data("initialized", true);
  526. if(found && termSelect.val() != stored) {
  527. selectTerm(stored);
  528. clickExecuteButton();
  529. }
  530. else if($(".grid_pagertable").size() == 0) {
  531. clickExecuteButton();
  532. }
  533. }
  534. }
  535. }, 500);
  536. },
  537.  
  538. /* Set all paginators to 500 items per page */
  539. fixPagination: function() {
  540. window.setInterval(function() {
  541. var pageSelect = $(".grid_pagerpanel select");
  542. pageSelect.each(function() {
  543. var e = $(this);
  544. e.hide();
  545. $(".link_pagesize", e.closest("tr")).html("");
  546. if(e.attr("data-listing") != "1" && e.val() != "500") {
  547. e.attr("data-listing", "1").val("500");
  548. var onChange = this.getAttributeNode("onchange");
  549. if(onChange) {
  550. npu.runEval(onChange.value);
  551. }
  552. }
  553. });
  554. }, 100);
  555. },
  556.  
  557. /* Hide countdown and send requests to the server to keep the session alive */
  558. initKeepSession: function() {
  559. var cdt = $("#hfCountDownTime");
  560. var timeout = 120;
  561. if(cdt.size() > 0) {
  562. var cdto = parseInt(cdt.val());
  563. if(cdto > 60) {
  564. timeout = cdto;
  565. }
  566. }
  567. var keepAlive = function() {
  568. window.setTimeout(function() {
  569. $.ajax({
  570. url: "main.aspx"
  571. });
  572. keepAlive();
  573. }, timeout * 1000 - 30000 - Math.floor(Math.random() * 30000));
  574. };
  575. keepAlive();
  576.  
  577. window.setInterval(function() {
  578. npu.runEval(function() {
  579. ShowModal = function() { };
  580. clearTimeout(timerID);
  581. clearTimeout(timerID2);
  582. sessionEndDate = null;
  583. });
  584. if($("#npuStatus").size() == 0) {
  585. $("#upTraining_lblRemainingTime").html('<span id="npuStatus" style="font-weight: normal"><a href="https://npu.herokuapp.com" target="_blank">Neptun PowerUp!</a> v' + GM_info["script"]["version"] + '</span>');
  586. }
  587. }, 1000);
  588. },
  589.  
  590. /* Use custom loading indicator for async requests */
  591. initProgressIndicator: function() {
  592. var color = $("#lbtnQuit").css("color");
  593. $(
  594. '<style type="text/css"> ' +
  595. '#npu_loading ' +
  596. '{ ' +
  597. 'position: fixed; ' +
  598. 'width: 150px; ' +
  599. 'margin-left: -75px; ' +
  600. 'left: 50%; ' +
  601. 'top: 0; ' +
  602. 'background: ' + color + '; ' +
  603. 'color: white; ' +
  604. 'font-size: 1.2em; ' +
  605. 'font-weight: bold; ' +
  606. 'padding: 8px 10px; ' +
  607. 'text-align: center; ' +
  608. 'z-index: 1000; ' +
  609. 'display: none; ' +
  610. '-webkit-border-bottom-right-radius: 5px; ' +
  611. '-webkit-border-bottom-left-radius: 5px; ' +
  612. '-moz-border-radius-bottomright: 5px; ' +
  613. '-moz-border-radius-bottomleft: 5px; ' +
  614. 'border-bottom-right-radius: 5px; ' +
  615. 'border-bottom-left-radius: 5px; ' +
  616. '-webkit-box-shadow: 0px 0px 3px 0px black; ' +
  617. '-moz-box-shadow: 0px 0px 3px 0px black; ' +
  618. 'box-shadow: 0px 0px 3px 0px black; ' +
  619. '} ' +
  620. '</style>'
  621. ).appendTo("head");
  622.  
  623. $("#progress, #customtextprogress").css("visibility", "hidden");
  624. $('<div id="npu_loading">Kis türelmet...</div>').appendTo("body");
  625.  
  626. npu.runEval(function() {
  627. var manager = Sys.WebForms.PageRequestManager.getInstance();
  628. manager.add_beginRequest(function(a, b) {
  629. $("#npu_loading").show();
  630. });
  631. manager.add_endRequest(function() {
  632. $("#npu_loading").hide();
  633. });
  634. });
  635. },
  636.  
  637. /* == TIMETABLE == */
  638.  
  639. /* Enhance timetable functionality */
  640. fixTimetable: function() {
  641. window.setInterval(function() {
  642. if($("#gridcontainer").attr("data-bound") != "1") {
  643. npu.runEval(function() {
  644. var options = $("#gridcontainer").BcalGetOp();
  645. if(typeof options != "undefined" && options != null) {
  646. $("#gridcontainer").attr("data-bound", "1");
  647. var callback = options.onAfterRequestData;
  648. options.onAfterRequestData = function(n) {
  649. if($("#gridcontainer").attr("data-called") != "1") {
  650. $("#gridcontainer").attr("data-called", "1");
  651. $("#upFunction_c_common_timetable_upTimeTable .showtoday").trigger("click");
  652. }
  653. callback(n);
  654. }
  655. }
  656. });
  657. }
  658. }, 100);
  659. },
  660.  
  661. /* == MARK LIST == */
  662.  
  663. /* Enhance mark list style */
  664. fixMarkList: function() {
  665. $(
  666. '<style type="text/css"> ' +
  667. '#h_markbook_gridIndexEntry_bodytable tr.SubjectCompletedRow td ' +
  668. '{ ' +
  669. 'background-color: #D5EFBA !important; ' +
  670. '} ' +
  671. '</style>'
  672. ).appendTo("head");
  673. },
  674.  
  675. /* == PROGRESS LIST == */
  676.  
  677. /* Enhance progress list style */
  678. fixProgressList: function() {
  679. $(
  680. '<style type="text/css"> ' +
  681. '#h_advance_gridSubjects_bodytable tr:not(.gridrow_blue):not(.gridrow_green) td, ' +
  682. '#h_advance_NonCurrTemp_bodytable tr:not(.gridrow_blue):not(.gridrow_green) td ' +
  683. '{ ' +
  684. 'background-color: #F8EFB1 !important; ' +
  685. 'font-weight: bold; ' +
  686. 'color: #525659; ' +
  687. '} ' +
  688. '#h_advance_gridSubjects_bodytable tr.gridrow_green td, ' +
  689. '#h_advance_NonCurrTemp_bodytable tr.gridrow_green td ' +
  690. '{ ' +
  691. 'background-color: #D5EFBA !important; ' +
  692. 'font-weight: bold; ' +
  693. 'color: #525659; ' +
  694. '} ' +
  695. '#h_advance_gridSubjects_bodytable tr.gridrow_blue td, ' +
  696. '#h_advance_NonCurrTemp_bodytable tr.gridrow_blue td ' +
  697. '{ ' +
  698. 'background-color: none !important; ' +
  699. 'color: #525659; ' +
  700. '} ' +
  701. '</style>'
  702. ).appendTo("head");
  703. },
  704.  
  705. /* == COURSE LIST == */
  706.  
  707. /* Enhance course list style and functionality */
  708. fixCourseList: function() {
  709. $(
  710. '<style type="text/css"> ' +
  711. '#h_addsubjects_gridSubjects_bodytable tr.Row1_Bold td, ' +
  712. '#Addsubject_course1_gridCourses_bodytable tr.Row1_sel td, ' +
  713. '#Addsubject_course1_gridCourses_grid_body_div tr.Row1_sel td, ' +
  714. '#Addsubject_course1_gridCourses_bodytable tr.Row1_Bold_sel td, ' +
  715. '#Addsubject_course1_gridCourses_grid_body_div tr.Row1_Bold_sel td, ' +
  716. '#h_addsubjects_gridSubjects_bodytable tr.context_selectedrow td ' +
  717. '{ ' +
  718. 'background-color: #F8EFB1 !important; ' +
  719. 'font-weight: bold; color: #525659; ' +
  720. '} ' +
  721. '#h_addsubjects_gridSubjects_bodytable tr, ' +
  722. '#Addsubject_course1_gridCourses_bodytable tr, ' +
  723. '#Addsubject_course1_gridCourses_grid_body_div tr ' +
  724. '{ ' +
  725. 'cursor: pointer; ' +
  726. '} ' +
  727. '#h_addsubjects_gridSubjects_bodytable tr.npu_completed td, ' +
  728. '#h_addsubjects_gridSubjects_bodytable tr.context_selectedrow[data-completed] td ' +
  729. '{ ' +
  730. 'background-color: #D5EFBA !important; ' +
  731. 'font-weight: bold; ' +
  732. 'color: #525659; ' +
  733. '} ' +
  734. '#h_addsubjects_gridSubjects_bodytable tr.context_selectedrow ' +
  735. '{ ' +
  736. 'border: 0 none !important; ' +
  737. 'border-bottom: 1px solid #D3D3D3 !important; ' +
  738. '} ' +
  739. '</style>'
  740. ).appendTo("head");
  741.  
  742. $("body").on("click", "#Addsubject_course1_gridCourses_bodytable tbody td, #Addsubject_course1_gridCourses_grid_body_div tbody td", function(e) {
  743. if($(e.target).closest("input[type=checkbox]").size() == 0 && $(e.target).closest("td[onclick]").size() == 0) {
  744. var checkbox = $("input[type=checkbox]", $(this).closest("tr")).get(0);
  745. checkbox.checked = !checkbox.checked;
  746. var obj = unsafeWindow[$("#Addsubject_course1_gridCourses_gridmaindiv").attr("instanceid")];
  747. try { obj.Cv($("input[type=checkbox]", $(this).closest("tr")).get(0), "1"); } catch(ex) { }
  748. e.preventDefault();
  749. return false;
  750. }
  751. });
  752.  
  753. $("body").on("click", "#h_addsubjects_gridSubjects_bodytable tbody td", function(e) {
  754. if($(e.target).closest("td[onclick], span.link").size() == 0 && $(e.target).closest("td.contextcell_sel, td.contextcell").size() == 0) {
  755. npu.runEval($("td span.link", $(this).closest("tr")).attr("onclick"));
  756. e.preventDefault();
  757. return false;
  758. }
  759. });
  760.  
  761. window.setInterval(function() {
  762. var table = $("#h_addsubjects_gridSubjects_bodytable");
  763. if(table.attr("data-painted") != "1") {
  764. table.attr("data-painted", "1");
  765. $("tbody tr", table).each(function() {
  766. if($('td[n="Completed"] img', this).size() != 0) {
  767. $(this).addClass("npu_completed").attr("data-completed", "1");
  768. }
  769. });
  770. }
  771. }, 250);
  772. },
  773.  
  774. /* Automatically press submit button on course list page */
  775. initCourseAutoList: function() {
  776. npu.runEval(function() {
  777. var manager = Sys.WebForms.PageRequestManager.getInstance();
  778. var courseListLoading = false;
  779. manager.add_beginRequest(function() {
  780. courseListLoading = true;
  781. });
  782. manager.add_endRequest(function() {
  783. courseListLoading = false;
  784. });
  785. window.setInterval(function() {
  786. if(!courseListLoading && $("#h_addsubjects_gridSubjects_gridmaindiv").size() == 0) {
  787. $("#upFilter_expandedsearchbutton").click();
  788. }
  789. }, 250);
  790. });
  791.  
  792. var updateTable = function() {
  793. $("#upFunction_h_addsubjects_upGrid").html("");
  794. };
  795.  
  796. $("body").on("change", "#upFilter_chkFilterCourses", updateTable);
  797. $("body").on("change", "#upFilter_rbtnSubjectType input[type=radio]", updateTable);
  798. },
  799.  
  800. /* Initialize course choice storage and mark subject and course lines with stored course choices */
  801. initCourseStore: function() {
  802. $(
  803. '<style type="text/css"> ' +
  804. '#h_addsubjects_gridSubjects_bodytable tr td.npu_choice_mark, ' +
  805. '#Addsubject_course1_gridCourses_bodytable tr td.npu_choice_mark, ' +
  806. '#Addsubject_course1_gridCourses_grid_body_div tr td.npu_choice_mark ' +
  807. '{ ' +
  808. 'background: #C00 !important; ' +
  809. '} ' +
  810. '</style>'
  811. ).appendTo("head");
  812.  
  813. var loadCourses = function() {
  814. courses = { };
  815. $.extend(courses, npu.getUserData(null, null, ["courses", "_legacy"]));
  816. $.extend(courses, npu.getUserData(null, null, ["courses", npu.training]));
  817. };
  818.  
  819. var refreshScreen = function() {
  820. $("#h_addsubjects_gridSubjects_bodytable").attr("data-choices-displayed", "0");
  821. $("#Addsubject_course1_gridCourses_bodytable").attr("data-inner-choices-displayed", "0");
  822. $("#Addsubject_course1_gridCourses_grid_body_div").attr("data-inner-choices-displayed", "0");
  823. };
  824.  
  825. var courses = null;
  826. loadCourses();
  827.  
  828. window.setInterval(function() {
  829. var table = $("#h_addsubjects_gridSubjects_bodytable");
  830. if(table.size() > 0 && table.attr("data-choices-displayed") != "1") {
  831. table.attr("data-choices-displayed", "1");
  832. var filterEnabled = npu.getUserData(null, null, "filterCourses");
  833. $("tbody tr", table).each(function() {
  834. var subjectCode = $("td:nth-child(3)", this).text().trim().toUpperCase();
  835. var choices = courses[subjectCode.trim().toUpperCase()];
  836. if(typeof choices != "undefined" && choices != null && choices.length > 0) {
  837. $("td:first-child", this).addClass("npu_choice_mark");
  838. $(this).css("display", "table-row");
  839. }
  840. else {
  841. $("td:first-child", this).removeClass("npu_choice_mark");
  842. $(this).css("display", filterEnabled ? "none" : "table-row");
  843. }
  844. });
  845.  
  846. var pager = $("#h_addsubjects_gridSubjects_gridmaindiv .grid_pagertable .grid_pagerpanel table tr");
  847. if($("#npu_clear_courses").size() == 0) {
  848. var clearAll = $('<td id="npu_clear_courses"><a style="color: #C00; line-height: 17px; margin-right: 30px" href="">Tárolt kurzusok törlése</a></td>');
  849. $("a", clearAll).click(function(e) {
  850. e.preventDefault();
  851. if(confirm(npu.user + " felhasználó összes tárolt kurzusa törölve lesz ezen a képzésen. Valóban ezt szeretnéd?")) {
  852. npu.setUserData(null, null, ["courses", npu.training], { });
  853. npu.setUserData(null, null, ["courses", "_legacy"], { });
  854. npu.setUserData(null, null, "filterCourses", false);
  855. npu.saveData();
  856. loadCourses();
  857. refreshScreen();
  858. }
  859. });
  860. pager.prepend(clearAll);
  861. }
  862. if($("#npu_filter_courses").size() == 0) {
  863. var filterCell = $('<td id="npu_filter_courses" style="padding-right: 30px; line-height: 17px"><input type="checkbox" id="npu_filter_field" style="vertical-align: middle" />&nbsp;&nbsp;<label for="npu_filter_field">Csak a tárolt kurzusok megjelenítése</label></td>');
  864. $("input", filterCell).change(function(e) {
  865. npu.setUserData(null, null, "filterCourses", $(this).get(0).checked);
  866. npu.saveData();
  867. refreshScreen();
  868. });
  869. pager.prepend(filterCell);
  870. }
  871. $("#npu_filter_field").get(0).checked = filterEnabled;
  872. }
  873.  
  874. var innerTable = $("#Addsubject_course1_gridCourses_bodytable:visible, #Addsubject_course1_gridCourses_grid_body_div:visible").first();
  875. if(innerTable.size() > 0 && innerTable.attr("data-inner-choices-displayed") != "1") {
  876. innerTable.attr("data-inner-choices-displayed", "1");
  877. if($("th.headerWithCheckbox", innerTable).size() == 0) {
  878. var objName = $("#Addsubject_course1_gridCourses_gridmaindiv").attr("instanceid");
  879. $('<th id="head_chk" class="headerWithCheckbox headerDisabled" colname="chk" title="Válasszon ki legalább egyet!" align="center"><label class="hiddenforlabel" for="Addsubject_course1_gridCourses_bodytable_chk_chkall">Összes kijelölése</label><span></span><input aria-disabled="false" role="checkbox" id="Addsubject_course1_gridCourses_bodytable_chk_chkall" onclick="' + objName + '.AllCheckBox(this.checked,\'chk\',true,1,this)" type="checkbox"><span></span></th>').appendTo("#Addsubject_course1_gridCourses_headerrow");
  880. $("tbody tr", innerTable).each(function() {
  881. $('<td t="chks" n="chk" class="aligncenter"><label class="hiddenforlabel" for="chk' + $(this).attr("id").substring(4) + '">' + $("td:nth-child(2)", this).text().trim() + '</label><input id="chk' + $(this).attr("id").substring(4) + '" aria-disabled="false" role="checkbox" onclick="' + objName + '.Cv(this,\'1\');" type="checkbox"></td>').appendTo(this);
  882. });
  883. }
  884. $("tbody tr", innerTable).each(function() {
  885. $("input[type=checkbox]", this).removeAttr("disabled");
  886. });
  887. var subjectText = $("#Subject_data_for_schedule_ctl00:visible > div > div > h2").html();
  888. if(subjectText != null) {
  889. var part = subjectText.split("<br>")[0];
  890. if(part.charAt(part.length - 1) == ')') {
  891. var depth = 0;
  892. for(var i = part.length - 2; i >= 0; i--) {
  893. var c = part.charAt(i);
  894. if(depth == 0 && c == '(') {
  895. var subjectCode = part.substring(i + 1, part.length - 1);
  896. break;
  897. }
  898. depth = c == ')' ? depth + 1 : depth;
  899. depth = c == '(' && depth > 0 ? depth - 1 : depth;
  900. }
  901. }
  902. if(typeof subjectCode != "undefined") {
  903. var choices = courses[subjectCode.trim().toUpperCase()];
  904. var hasChoices = (typeof choices != "undefined" && choices != null && choices.length > 0);
  905. if(hasChoices) {
  906. $("tbody tr", innerTable).each(function() {
  907. var courseCode = $("td:nth-child(2)", this).text().trim().toUpperCase();
  908. if($.inArray(courseCode, choices) != -1) {
  909. $("td:first-child", this).addClass("npu_choice_mark");
  910. }
  911. else {
  912. $("td:first-child", this).removeClass("npu_choice_mark");
  913. }
  914. });
  915. }
  916. else {
  917. $("tbody tr td:first-child", innerTable).removeClass("npu_choice_mark");
  918. }
  919. if($(".npu_course_choice_actions").size() == 0) {
  920. var header = $("#Addsubject_course1_gridCourses_gridmaindiv .grid_functiontable_top .functionitem");
  921. var footer = $("#Addsubject_course1_gridCourses_tablebottom .grid_functiontable_bottom .functionitem");
  922. var canSave = header.size() > 0;
  923. if(header.size() == 0) {
  924. $('<table class="grid_functiontable_top" align="left"><tbody><tr><td class="functionitem" nowrap=""></td></tr></tbody></table>').appendTo("#Addsubject_course1_gridCourses_gridmaindiv .grid_topfunctionpanel");
  925. header = $(header.selector);
  926. }
  927. if(footer.size() == 0) {
  928. $('<table class="grid_functiontable_bottom" align="right"><tbody><tr><td class="functionitem" nowrap=""></td></tr></tbody></table>').appendTo("#Addsubject_course1_gridCourses_tablebottom .grid_bottomfunctionpanel");
  929. footer = $(footer.selector);
  930. }
  931. var buttonBarExtensions = $('<span class="npu_course_choice_actions" style="margin: 0 20px"><span class="FunctionCommandTitle">Tárolt kurzusok:</span><input type="button" value="Tárolás" class="gridbutton npu_course_choice_save"><input type="button" value="Betöltés" class="gridbutton npu_course_choice_load" style="display: none">' + (canSave ? '<input type="button" value="Betöltés és Mentés" class="gridbutton npu_course_choice_apply" style="display: none">' : "") + '<input type="button" value="Törlés" class="gridbutton npu_course_choice_delete" style="display: none"></span>');
  932. header.append(buttonBarExtensions);
  933. footer.prepend(buttonBarExtensions.clone());
  934. $(".npu_course_choice_actions .npu_course_choice_save").click(function() {
  935. var selectedCourses = [];
  936. $("tbody tr", innerTable).each(function() {
  937. var courseCode = $("td:nth-child(2)", this).text().trim().toUpperCase();
  938. var checkbox = $("input[type=checkbox]", this).get(0);
  939. if(checkbox.checked) {
  940. selectedCourses.push(courseCode);
  941. }
  942. });
  943. if(selectedCourses.length == 0) {
  944. alert("A tároláshoz előbb válaszd ki a tárolandó kurzusokat.");
  945. }
  946. else {
  947. npu.setUserData(null, null, ["courses", npu.training, subjectCode.trim().toUpperCase()], selectedCourses);
  948. npu.saveData();
  949. loadCourses();
  950. refreshScreen();
  951. }
  952. });
  953. $(".npu_course_choice_actions .npu_course_choice_load").click(function() {
  954. $("tbody tr", innerTable).each(function() {
  955. var courseCode = $("td:nth-child(2)", this).text().trim().toUpperCase();
  956. var checkbox = $("input[type=checkbox]", this).get(0);
  957. checkbox.checked = $.inArray(courseCode, courses[subjectCode.trim().toUpperCase()]) != -1;
  958. var obj = unsafeWindow[$("#Addsubject_course1_gridCourses_gridmaindiv").attr("instanceid")];
  959. try { obj.Cv(checkbox, "1"); } catch(ex) { }
  960. });
  961. });
  962. $(".npu_course_choice_actions .npu_course_choice_apply").click(function() {
  963. npu.runEval(function() {
  964. $(".npu_course_choice_actions .npu_course_choice_load").trigger("click");
  965. });
  966. var obj = unsafeWindow[$("#Addsubject_course1_gridCourses_gridmaindiv").attr("instanceid")];
  967. try { obj.SelectFunction("update"); } catch(ex) { }
  968. });
  969. $(".npu_course_choice_actions .npu_course_choice_delete").click(function() {
  970. if(confirm("Valóban törölni szeretnéd a tárolt kurzusokat?")) {
  971. npu.setUserData(null, null, ["courses", npu.training, subjectCode.trim().toUpperCase()], null);
  972. npu.setUserData(null, null, ["courses", "_legacy", subjectCode.trim().toUpperCase()], null);
  973. npu.saveData();
  974. loadCourses();
  975. refreshScreen();
  976. }
  977. });
  978. }
  979. $(".npu_course_choice_load, .npu_course_choice_apply, .npu_course_choice_delete", $(".npu_course_choice_actions")).css("display", hasChoices ? "inline" : "none");
  980. }
  981. }
  982. }
  983. }, 500);
  984. },
  985.  
  986. /* == EXAM LIST == */
  987.  
  988. /* Enhance exam list style and functionality */
  989. fixExamList: function() {
  990. $('<style type="text/css"> #h_exams_gridExamList_bodytable tr.gridrow_blue td { background: #F8EFB1 !important; font-weight: bold; color: #525659 !important; } #h_exams_gridExamList_bodytable tr { cursor: pointer; } </style>').appendTo("head");
  991. $("body").on("click", "#h_exams_gridExamList_bodytable tbody td", function(e) {
  992. if($(e.target).closest("td[onclick], td.contextcell_sel, td.contextcell").size() == 0) {
  993. npu.runEval(function() {
  994. $("td.contextcell, td.contextcell_sel", $(this).closest("tr")).trigger("click");
  995. });
  996. e.preventDefault();
  997. return false;
  998. }
  999. });
  1000. },
  1001.  
  1002. /* Automatically list exams on page load and subject change */
  1003. initExamAutoList: function() {
  1004. $('<style type="text/css"> #upFilter_bodytable tr.nostyle { display: none } </style>').appendTo("head");
  1005. $("body").on("change", "#upFilter_cmbSubjects", function() {
  1006. $.examListSubjectValue = $(this).val();
  1007. });
  1008. window.setInterval(function() {
  1009. var panel = $("#upFilter_panFilter table.searchpanel");
  1010. if(panel.attr("data-listing") != "1" && ($.examListTerm != $("#upFilter_cmbTerms option[selected]").attr("value") || $.examListSubject != $.examListSubjectValue)) {
  1011. panel.attr("data-listing", "1");
  1012. $.examListTerm = $("#upFilter_cmbTerms option[selected]").attr("value");
  1013. $.examListSubject = $.examListSubjectValue;
  1014. npu.runEval(function() {
  1015. $("#upFilter_expandedsearchbutton").click();
  1016. });
  1017. }
  1018. }, 100);
  1019. },
  1020.  
  1021. /* == STATISTICS == */
  1022.  
  1023. /* Statistics server URL */
  1024. statHost: "http://npu.herokuapp.com/stat",
  1025.  
  1026. /* Initialize statistics */
  1027. initStat: function() {
  1028. var code = npu.getUserData(null, null, ["statCode"]);
  1029. if(code == null) {
  1030. code = npu.generateToken();
  1031. npu.setUserData(null, null, ["statSalt"], null);
  1032. npu.setUserData(null, null, ["statCode"], code);
  1033. npu.saveData();
  1034. }
  1035. setTimeout(function() {
  1036. try {
  1037. var h = new npu.jsSHA(npu.user + ":" + code, "TEXT").getHash("SHA-256", "HEX");
  1038. GM_xmlhttpRequest({
  1039. method: "POST",
  1040. data: $.param({
  1041. version: GM_info["script"]["version"],
  1042. domain: npu.domain,
  1043. user: h.substring(0, 32),
  1044. uri: window.location.href
  1045. }),
  1046. headers: {
  1047. "Content-Type": "application/x-www-form-urlencoded"
  1048. },
  1049. synchronous: false,
  1050. timeout: 10000,
  1051. url: npu.statHost
  1052. });
  1053. }
  1054. catch(e) { }
  1055. }, 5000);
  1056. },
  1057.  
  1058. /* == MISC == */
  1059.  
  1060. /* Verify that we are indeed on a Neptun page */
  1061. isNeptunPage: function() {
  1062. return document.title.indexOf("Neptun.Net") != -1;
  1063. },
  1064.  
  1065. /* Initialize and cache parameters that do not change dynamically */
  1066. initParameters: function() {
  1067. npu.user = npu.getUser();
  1068. npu.domain = npu.getDomain();
  1069. npu.training = npu.getTraining();
  1070. },
  1071.  
  1072. /* Parses and returns the first-level domain of the site */
  1073. getDomain: function() {
  1074. var domain = "", host = location.host.split(".");
  1075. var tlds = ["at", "co", "com", "edu", "eu", "gov", "hu", "hr", "info", "int", "mil", "net", "org", "ro", "rs", "sk", "si", "ua", "uk"];
  1076. for(var i = host.length - 1; i >= 0; i--) {
  1077. domain = host[i] + "." + domain;
  1078. if($.inArray(host[i], tlds) == -1) {
  1079. return domain.substring(0, domain.length - 1);
  1080. }
  1081. }
  1082. },
  1083.  
  1084. /* Parses and returns the ID of the current user */
  1085. getUser: function() {
  1086. if($("#upTraining_topname").size() > 0) {
  1087. var input = $("#upTraining_topname").text();
  1088. return input.substring(input.indexOf(" - ") + 3).toUpperCase();
  1089. }
  1090. },
  1091.  
  1092. /* Parses and returns the sanitized name of the current training */
  1093. getTraining: function() {
  1094. if($("#lblTrainingName").size() > 0) {
  1095. return $("#lblTrainingName").text().replace(/[^a-zA-Z0-9]/g, "");
  1096. }
  1097. },
  1098.  
  1099. /* Returns whether we are on the login page */
  1100. isLogin: function() {
  1101. return $("td.login_left_side").size() > 0;
  1102. },
  1103.  
  1104. /* Returns the ID of the current page */
  1105. getPage: function() {
  1106. var result = (/ctrl=([a-zA-Z0-9_]+)/g).exec(window.location.href);
  1107. return result ? result[1] : null;
  1108. },
  1109.  
  1110. /* Returns whether the specified ID is the current page */
  1111. isPage: function(ctrl) {
  1112. return (window.location.href.indexOf("ctrl=" + ctrl) != -1);
  1113. },
  1114.  
  1115. /* Runs a function asynchronously to fix problems in certain cases */
  1116. runAsync: function(func) {
  1117. window.setTimeout(func, 0);
  1118. },
  1119.  
  1120. /* Evaluates code in the page context */
  1121. runEval: function(source) {
  1122. if ("function" == typeof source) {
  1123. source = "(" + source + ")();"
  1124. }
  1125. var script = document.createElement('script');
  1126. script.setAttribute("type", "application/javascript");
  1127. script.textContent = source;
  1128. document.body.appendChild(script);
  1129. document.body.removeChild(script);
  1130. },
  1131.  
  1132. /* Returns the child object at the provided path */
  1133. getChild: function(o, s) {
  1134. while(s.length) {
  1135. var n = s.shift();
  1136. if(!(o instanceof Object && n in o)) {
  1137. return;
  1138. }
  1139. o = o[n];
  1140. }
  1141. return o;
  1142. },
  1143.  
  1144. /* Set the child object at the provided path */
  1145. setChild: function(o, s, v) {
  1146. while(s.length) {
  1147. var n = s.shift();
  1148. if(s.length == 0) {
  1149. if(v == null) {
  1150. delete o[n];
  1151. }
  1152. else {
  1153. o[n] = v;
  1154. }
  1155. return;
  1156. }
  1157. if(!(typeof o == "object" && n in o)) {
  1158. o[n] = new Object();
  1159. }
  1160. o = o[n];
  1161. }
  1162. },
  1163.  
  1164. /* Generates a random token */
  1165. generateToken: function() {
  1166. var text = "", possible = "0123456789abcdef";
  1167. for(var i = 0; i < 32; i++) {
  1168. text += possible.charAt(Math.floor(Math.random() * possible.length));
  1169. }
  1170. return text;
  1171. },
  1172.  
  1173. /* Encodes a string into base64 */
  1174. encodeBase64: function(data) {
  1175. var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  1176. var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, enc = "", tmp_arr = [];
  1177. if(!data) {
  1178. return data;
  1179. }
  1180. do {
  1181. o1 = data.charCodeAt(i++); o2 = data.charCodeAt(i++); o3 = data.charCodeAt(i++);
  1182. bits = o1 << 16 | o2 << 8 | o3;
  1183. h1 = bits >> 18 & 0x3f; h2 = bits >> 12 & 0x3f; h3 = bits >> 6 & 0x3f; h4 = bits & 0x3f;
  1184. tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
  1185. } while(i < data.length);
  1186. enc = tmp_arr.join("");
  1187. var r = data.length % 3;
  1188. return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3);
  1189. },
  1190.  
  1191. /* Decodes a string from base64 */
  1192. decodeBase64: function(data) {
  1193. var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  1194. var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, dec = "", tmp_arr = [];
  1195. if (!data) {
  1196. return data;
  1197. }
  1198. data += "";
  1199. do {
  1200. h1 = b64.indexOf(data.charAt(i++)); h2 = b64.indexOf(data.charAt(i++)); h3 = b64.indexOf(data.charAt(i++)); h4 = b64.indexOf(data.charAt(i++));
  1201. bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
  1202. o1 = bits >> 16 & 0xff; o2 = bits >> 8 & 0xff; o3 = bits & 0xff;
  1203. tmp_arr[ac++] = (h3 == 64 ? String.fromCharCode(o1) : (h4 == 64 ? String.fromCharCode(o1, o2) : String.fromCharCode(o1, o2, o3)));
  1204. } while(i < data.length);
  1205. dec = tmp_arr.join("");
  1206. return dec;
  1207. },
  1208. };
  1209.  
  1210. /*
  1211. A JavaScript implementation of the SHA family of hashes, as
  1212. defined in FIPS PUB 180-2 as well as the corresponding HMAC implementation
  1213. as defined in FIPS PUB 198a
  1214.  
  1215. Copyright Brian Turek 2008-2013
  1216. Distributed under the BSD License
  1217. See http://caligatio.github.com/jsSHA/ for more information
  1218.  
  1219. Several functions taken from Paul Johnston
  1220. */
  1221. (function(B){function r(a,c,b){var f=0,e=[0],g="",h=null,g=b||"UTF8";if("UTF8"!==g&&"UTF16"!==g)throw"encoding must be UTF8 or UTF16";if("HEX"===c){if(0!==a.length%2)throw"srcString of HEX type must be in byte increments";h=u(a);f=h.binLen;e=h.value}else if("ASCII"===c||"TEXT"===c)h=v(a,g),f=h.binLen,e=h.value;else if("B64"===c)h=w(a),f=h.binLen,e=h.value;else throw"inputFormat must be HEX, TEXT, ASCII, or B64";this.getHash=function(a,c,b,g){var h=null,d=e.slice(),l=f,m;3===arguments.length?"number"!==
  1222. typeof b&&(g=b,b=1):2===arguments.length&&(b=1);if(b!==parseInt(b,10)||1>b)throw"numRounds must a integer >= 1";switch(c){case "HEX":h=x;break;case "B64":h=y;break;default:throw"format must be HEX or B64";}if("SHA-224"===a)for(m=0;m<b;m++)d=q(d,l,a),l=224;else if("SHA-256"===a)for(m=0;m<b;m++)d=q(d,l,a),l=256;else throw"Chosen SHA variant is not supported";return h(d,z(g))};this.getHMAC=function(a,b,c,h,k){var d,l,m,n,A=[],s=[];d=null;switch(h){case "HEX":h=x;break;case "B64":h=y;break;default:throw"outputFormat must be HEX or B64";
  1223. }if("SHA-224"===c)l=64,n=224;else if("SHA-256"===c)l=64,n=256;else throw"Chosen SHA variant is not supported";if("HEX"===b)d=u(a),m=d.binLen,d=d.value;else if("ASCII"===b||"TEXT"===b)d=v(a,g),m=d.binLen,d=d.value;else if("B64"===b)d=w(a),m=d.binLen,d=d.value;else throw"inputFormat must be HEX, TEXT, ASCII, or B64";a=8*l;b=l/4-1;l<m/8?(d=q(d,m,c),d[b]&=4294967040):l>m/8&&(d[b]&=4294967040);for(l=0;l<=b;l+=1)A[l]=d[l]^909522486,s[l]=d[l]^1549556828;c=q(s.concat(q(A.concat(e),a+f,c)),a+n,c);return h(c,
  1224. z(k))}}function v(a,c){var b=[],f,e=[],g=0,h;if("UTF8"===c)for(h=0;h<a.length;h+=1)for(f=a.charCodeAt(h),e=[],2048<f?(e[0]=224|(f&61440)>>>12,e[1]=128|(f&4032)>>>6,e[2]=128|f&63):128<f?(e[0]=192|(f&1984)>>>6,e[1]=128|f&63):e[0]=f,f=0;f<e.length;f+=1)b[g>>>2]|=e[f]<<24-g%4*8,g+=1;else if("UTF16"===c)for(h=0;h<a.length;h+=1)b[g>>>2]|=a.charCodeAt(h)<<16-g%4*8,g+=2;return{value:b,binLen:8*g}}function u(a){var c=[],b=a.length,f,e;if(0!==b%2)throw"String of HEX type must be in byte increments";for(f=0;f<
  1225. b;f+=2){e=parseInt(a.substr(f,2),16);if(isNaN(e))throw"String of HEX type contains invalid characters";c[f>>>3]|=e<<24-f%8*4}return{value:c,binLen:4*b}}function w(a){var c=[],b=0,f,e,g,h,k;if(-1===a.search(/^[a-zA-Z0-9=+\/]+$/))throw"Invalid character in base-64 string";f=a.indexOf("=");a=a.replace(/\=/g,"");if(-1!==f&&f<a.length)throw"Invalid '=' found in base-64 string";for(e=0;e<a.length;e+=4){k=a.substr(e,4);for(g=h=0;g<k.length;g+=1)f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(k[g]),
  1226. h|=f<<18-6*g;for(g=0;g<k.length-1;g+=1)c[b>>2]|=(h>>>16-8*g&255)<<24-b%4*8,b+=1}return{value:c,binLen:8*b}}function x(a,c){var b="",f=4*a.length,e,g;for(e=0;e<f;e+=1)g=a[e>>>2]>>>8*(3-e%4),b+="0123456789abcdef".charAt(g>>>4&15)+"0123456789abcdef".charAt(g&15);return c.outputUpper?b.toUpperCase():b}function y(a,c){var b="",f=4*a.length,e,g,h;for(e=0;e<f;e+=3)for(h=(a[e>>>2]>>>8*(3-e%4)&255)<<16|(a[e+1>>>2]>>>8*(3-(e+1)%4)&255)<<8|a[e+2>>>2]>>>8*(3-(e+2)%4)&255,g=0;4>g;g+=1)b=8*e+6*g<=32*a.length?b+
  1227. "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(h>>>6*(3-g)&63):b+c.b64Pad;return b}function z(a){var c={outputUpper:!1,b64Pad:"="};try{a.hasOwnProperty("outputUpper")&&(c.outputUpper=a.outputUpper),a.hasOwnProperty("b64Pad")&&(c.b64Pad=a.b64Pad)}catch(b){}if("boolean"!==typeof c.outputUpper)throw"Invalid outputUpper formatting option";if("string"!==typeof c.b64Pad)throw"Invalid b64Pad formatting option";return c}function k(a,c){return a>>>c|a<<32-c}function I(a,c,b){return a&
  1228. c^~a&b}function J(a,c,b){return a&c^a&b^c&b}function K(a){return k(a,2)^k(a,13)^k(a,22)}function L(a){return k(a,6)^k(a,11)^k(a,25)}function M(a){return k(a,7)^k(a,18)^a>>>3}function N(a){return k(a,17)^k(a,19)^a>>>10}function O(a,c){var b=(a&65535)+(c&65535);return((a>>>16)+(c>>>16)+(b>>>16)&65535)<<16|b&65535}function P(a,c,b,f){var e=(a&65535)+(c&65535)+(b&65535)+(f&65535);return((a>>>16)+(c>>>16)+(b>>>16)+(f>>>16)+(e>>>16)&65535)<<16|e&65535}function Q(a,c,b,f,e){var g=(a&65535)+(c&65535)+(b&
  1229. 65535)+(f&65535)+(e&65535);return((a>>>16)+(c>>>16)+(b>>>16)+(f>>>16)+(e>>>16)+(g>>>16)&65535)<<16|g&65535}function q(a,c,b){var f,e,g,h,k,q,r,C,u,d,l,m,n,A,s,p,v,w,x,y,z,D,E,F,G,t=[],H,B=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,
  1230. 3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];d=[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428];f=[1779033703,3144134277,1013904242,
  1231. 2773480762,1359893119,2600822924,528734635,1541459225];if("SHA-224"===b||"SHA-256"===b)l=64,A=16,s=1,G=Number,p=O,v=P,w=Q,x=M,y=N,z=K,D=L,F=J,E=I,d="SHA-224"===b?d:f;else throw"Unexpected error in SHA-2 implementation";a[c>>>5]|=128<<24-c%32;a[(c+65>>>9<<4)+15]=c;H=a.length;for(m=0;m<H;m+=A){c=d[0];f=d[1];e=d[2];g=d[3];h=d[4];k=d[5];q=d[6];r=d[7];for(n=0;n<l;n+=1)t[n]=16>n?new G(a[n*s+m],a[n*s+m+1]):v(y(t[n-2]),t[n-7],x(t[n-15]),t[n-16]),C=w(r,D(h),E(h,k,q),B[n],t[n]),u=p(z(c),F(c,f,e)),r=q,q=k,k=
  1232. h,h=p(g,C),g=e,e=f,f=c,c=p(C,u);d[0]=p(c,d[0]);d[1]=p(f,d[1]);d[2]=p(e,d[2]);d[3]=p(g,d[3]);d[4]=p(h,d[4]);d[5]=p(k,d[5]);d[6]=p(q,d[6]);d[7]=p(r,d[7])}if("SHA-224"===b)a=[d[0],d[1],d[2],d[3],d[4],d[5],d[6]];else if("SHA-256"===b)a=d;else throw"Unexpected error in SHA-2 implementation";return a}"function"===typeof define&&typeof define.amd?define(function(){return r}):"undefined"!==typeof exports?"undefined"!==typeof module&&module.exports?module.exports=exports=r:exports=r:B.jsSHA=r})(npu);
  1233.  
  1234. /* Run the script */
  1235. npu.init();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement