Spectrum Advanced

This script is designed to help users automatically log into the University of Malaya's SPeCTRUM system(by sending request).

安裝腳本?
作者推薦腳本

您可能也會喜歡 UMLib Autologin

安裝腳本
  1. // ==UserScript==
  2. // @name Spectrum Advanced
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description This script is designed to help users automatically log into the University of Malaya's SPeCTRUM system(by sending request).
  6. // @author Koukotsukan Neo
  7. // @match https://casv.um.edu.my/cas/loginAllType?service=*
  8. // @match https://spectrum.um.edu.my
  9. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  10. // @grant GM_xmlhttpRequest
  11. // @grant GM_getValue
  12. // @grant GM_setValue
  13. // @grant GM_deleteValue
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. const curURL = window.location.href;
  18. const match = (...patterns) => patterns.some(p => curURL.includes(p));
  19. var data2 = "";
  20. if (match("https://spectrum.um.edu.my")) {
  21. if (document.querySelector("span.login").querySelector("a")) {
  22. var z= document.createElement('a');
  23. z.setAttribute("href","javascript:void(0);");
  24. z.setAttribute("id","helper");
  25. z.innerText='Spectrum Advanced';
  26. console.log(document.querySelectorAll("div[class=\"usermenu\"]")[0])
  27. document.querySelectorAll("div[class=\"infoarea \"]")[0].appendChild(z);
  28. document.querySelector ("#helper").addEventListener("click", doAdd, false);
  29. if (GM_getValue('status') == 1 && GM_getValue('pwd') && GM_getValue('uname')){
  30. GM_xmlhttpRequest ({
  31. method: "GET",
  32. url: "https://sso.um.edu.my/cas/loginAllType?service=https://spectrum.um.edu.my/login/index.php",
  33. headers: {
  34. "Content-Type": "text/html; charset=utf-8"
  35. },
  36. onload: function(res){
  37. if(res.status === 200){
  38. console.log(res.responseHeaders)
  39. console.log(res.response)
  40. console.log('Success Visit')
  41. var html = res.responseText
  42. var patt = /<input type="hidden" name="lt" value="(.*)" \/>/i;
  43. var lt = html.match(patt)[1]
  44. data2 = "uname=" + GM_getValue('uname') +"&password=" + GM_getValue('pwd') + "&domain=%40perdana.um.edu.my&lt=" + lt + "&_eventId=submit&username="+GM_getValue('uname')+"%40perdana.um.edu.my"
  45. GM_xmlhttpRequest ({
  46. method: "POST",
  47. url: "https://sso.um.edu.my/cas/loginAllType?service=https://spectrum.um.edu.my/login/index.php",
  48. data: data2,
  49. headers: {
  50. "Content-Type": "application/x-www-form-urlencoded"
  51. },
  52. onload: function(res){
  53. if(res.status === 200){
  54. //console.log(res.responseHeaders)
  55. //console.log(res.response)
  56. var patt2 = /<div class="error" style="color: red; font-size: 1em;">The credentials you provided cannot be found or please select different Status.<p\/><\/div>/
  57. if(!res.responseText.match(patt2)){
  58. console.log('Success Login')
  59. location.href="https://spectrum.um.edu.my";
  60. }else{
  61. console.log('Incorrect Credentials')
  62. alert("credentials not correct, please reset them")
  63. doAdd()
  64. }
  65. }else{
  66. console.log('Login Failed')
  67. console.log(res)
  68. }
  69. },
  70. onerror : function(err){
  71. console.log('Error Login')
  72. console.log(err)
  73. }
  74. });
  75. }else{
  76. console.log('Fail Visit')
  77. console.log(res)
  78. }
  79. },
  80. onerror : function(err){
  81. console.log('Error Visit')
  82. console.log(err)
  83. }
  84. });
  85. }
  86. }
  87. }
  88. function doAdd(){
  89. var uname = prompt("Username", "");
  90. var password = prompt("Password","");
  91. GM_setValue('uname',uname);
  92. GM_setValue("pwd", password);
  93. GM_setValue("status",1);
  94. location.reload();
  95. }
  96. }
  97. )();