diff --git a/img/normal.png b/img/normal.png new file mode 100644 index 0000000..1489639 Binary files /dev/null and b/img/normal.png differ diff --git a/js/patch.js b/js/patch.js index e4d83ac..850a9d4 100644 --- a/js/patch.js +++ b/js/patch.js @@ -1,20 +1,110 @@ -// alert("It works"); -if(document.getElementsByName("userpwd_text")[0] !== undefined){ +var isStop = true; +var ClickTwice = false; +var kh_Array_pub = ["", "", "", ""]; + +function QK_loop(kh_Array) { + if (kh_Array.length != 4) { + return false; + } else { + isStop = false; + function t(Arr) { + if (!QiangKe(Arr[0], Arr[1], Arr[2], Arr[3])) + { + isStop = true; + return false; + } + //===Waiting Loop==== + function _(times, len) { + if (times > 0) { + if (ClickTwice) { + ClickTwice = false; + isStop = true; + } + if (isStop) return; + setTimeout(_, len, times - 1, len) + } else { + t(Arr); + } + } + _(20, 250); + //======= + kh_Array_pub = kh_Array; + return true; + } + return t(kh_Array); + } +} + +function QiangKe(kh1, kh2, kh3, kh4) { + try { + F = document.getElementsByName('mainFrame')[0].contentDocument; + F.getElementsByName('xkxh1')[0].value = kh1 || ""; + F.getElementsByName('xkxh2')[0].value = kh2 || ""; + F.getElementsByName('xkxh3')[0].value = kh3 || ""; + F.getElementsByName('xkxh4')[0].value = kh4 || ""; + } catch(e) { + return false; + } + if (! (!kh1 && !kh2 && !kh3 && !kh4)) { + setTimeout(function() { + F.getElementsByName('xuanke')[0].click(); + }, + 500); + return true; + } else { + return false; + } +} + +chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { + console.log("RUN"); + if (request['isStop'] !== undefined) { + + if (request['isStop']) { + isStop = request['isStop']; + sendResponse("Stopped"); + } else { + if(!isStop){ + isStop = true; + ClickTwice = true; + sendResponse("Stopped"); + } + else{ + var G = QK_loop(request['kh_Array']); + if (G) { + sendResponse("Started"); + } else { + sendResponse("Stopped"); + } + } + } + } else { + sendResponse(isStop ? ["Stopped", ""]: ["Started", kh_Array_pub]) + } +}); + +//==========下面的别动======== +if (document.getElementsByName("userpwd_text")[0] !== undefined) { document.getElementsByName("userpwd_text")[0].id = "userpwd_text"; } -// slidebar on the left -var contnt = window.top.document.getElementsByName("leftFrame")[0].contentDocument; -if (contnt !== undefined){ - var topLine = contnt.getElementById("MFX0").style["top"]; - var attrHeight = 12 - topLine = parseInt(topLine); - for (var i = 0; i < 21; i++) { - var MFX = contnt.getElementById("MFX" + i); - if (MFX){ - var attrTop = topLine + i * attrHeight; - MFX.style["visibility"]= "visible"; - MFX.style["top"] = attrTop.toString() + "px"; +function Patch_web() { + var aa = window.top.document.getElementsByName("leftFrame")[0]; + if (aa !== undefined) { + aa = aa.contentDocument; + var t = 110; + for (var i = 0; i < 21; i++) { + var tmp = aa.getElementById('MFX' + i); + if (tmp) { + tmp.style["visibility"] = 'visible'; + tmp.style["top"] = t + 'px'; + t = t + 12; + } } } } + +window.onload = function() { + console.log("ZAIRU"); + Patch_web(); +} \ No newline at end of file diff --git a/js/pop.js b/js/pop.js new file mode 100644 index 0000000..188a8f3 --- /dev/null +++ b/js/pop.js @@ -0,0 +1,112 @@ +var BaseImg = document.createElement('img') +BaseImg.setAttribute( "src", + "data:image/bmp;base64,Qk0uBgAAAAAAAIoAAAB8AAAAEwAAABMAAAABACAAAwAAAKQFAABiAQAAYgEAAAAAAAAAAAAAAAD/AAD/AAD/AAAAAAAA/0JHUnOAwvUoYLgeFSCF6wFAMzMTgGZmJkBmZgagmZkJPArXAyRcjzIAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAP///wD///9///////////////9z////AP///wD///8e////x////x7///8A////f/////////////////7+/qD+/v4K/v7+AAAAAAD///8A////gP/////////o////Kf///wD///8A////Hv///8f///8e////AP///4D//////////////97+/v4k////AP///wsAAAAA////AP///3//////////s/7+/gv+/v4A////AP///x7////H////Hv///wD///9///////////X+/v5d////AP///wv///+XAAAAAP///wD///9//////////37///8A////AP///wD///8e////x////x7///8A////gP////////+o/v7+Cv///wD///9Y////9AAAAAD///8A////gP////r///9R////AP7+/gD///8A////Hv///8f///8e////AP///4L////h/v7+Jf///wD///8j////2/////8AAAAA////AP///4L////b////F////wD///8A////AP///x7////H////Hv///wD///91/v7+ZP///wD///8K////oP//////////AAAAAP///wD///+E////lP///wD///8P////L////wD///8e////x////x7///8A/v7+NP7+/g////8A////Wf////T//////////wAAAAD///8A////df///1P///8A////L////2n///8A////Hv///8f///8e////AP///wD///8A////JP///9n///////////////8AAAAA////AP///2T///8g////AP///3X///9/////AP///x7////H////Hv///wD+/v4A/v7+Cv///6L/////////////////////AAAAAP///wD///8y////D////wv///+3////g////wD///8e////x////x7///8A/Pz8Av///2D////1/////////////////////wAAAAD///8A////AP///wD///8b////6P///4H///8A////Hv///8f///8e////AP7+/gj///+Y//////////////////////////8AAAAA////AP7+/gD///8A////Tv////n///+A////AP///x7////H////Hv///wD///8A/v7+Gv///6b/////////////////////AAAAAAAAAAD+/v4AKCgoAP///4//////////f////wD///8e////x////x7///8A////AP///wD+/v4Y////pf///////////////wAAAAAAAAAA////AP///xf////W/////////3////8A////Hv///8f///8e////AP7+/jn+/v4e/v7+AP///xf///+l//////////8AAAAAAAAAAP///wD///8q////6P////////9/////AP///x7////H////Hv///wD///9/////sv7+/hn+/v4A////Fv///6X/////AAAAAP///wD///8A////cv//////////////f////wD///8e////x////x7///8A////gP////////+t/v7+GP7+/gD///8Y////mgAAAAD+/v4A/v7+C////7T//////////////4D///8A////Hv///8f///8e////AP///3///////////////63+/v4X/v7+AP///wsAAAAA////AP///yn////o//////////////9/////AP///x7////H////Hv///wD///9/////////////////////rf7+/hj+/v4AAAAAAP///wD///9z////////////////////f////wD///8e////x////x7///8A////f//////////////////////+/v6f/v7+Cw==" + ); + +function makeIcon(isRun) +{ + var C = document.createElement("canvas"); + var J = C.getContext('2d'); + J.fillStyle = isRun?"#FF0000":"#000000"; + J.fillRect(0, 0, 19, 19); + J.drawImage(BaseImg,0, 0); + return { imageData: J.getImageData(0, 0, 19, 19) }; +} + +function ChangeStatus(sta) { + document.getElementById("status").innerHTML = sta; + //======Change Icon======== + chrome.browserAction.setIcon( makeIcon((sta=="Started")) ); + //====================== +} + +function fill(Arr){ + document.getElementById('xk1').value = Arr[0]; + document.getElementById('xk2').value = Arr[1]; + document.getElementById('xk3').value = Arr[2]; + document.getElementById('xk4').value = Arr[3]; +} + + +function sta() { + var Arr = []; + Arr.push(document.getElementById('xk1').value); + Arr.push(document.getElementById('xk2').value); + Arr.push(document.getElementById('xk3').value); + Arr.push(document.getElementById('xk4').value); + chrome.tabs.getSelected(null, + function(tab) { + chrome.tabs.sendMessage(tab.id, { + "isStop": false, + "kh_Array": Arr, + }, + function(response) { + ChangeStatus(response); + }); + }); +} +function end() { + chrome.tabs.getSelected(null, + function(tab) { + chrome.tabs.sendMessage(tab.id, { + "isStop": true + }, + function(response) { + ChangeStatus(response); + }); + }); +} + +function Par(url) { + var pattern = /^(?:(\w+):\/\/)?(?:(\w+):?(\w+)?@)?([^:\/\?#]+)(?::(\d+))?(\/[^\?#]+)?(?:\?([^#]+))?(?:#(\w+))?/; + var result = pattern.exec(url); + return result; +} + +function clone(destination, source) { + for (var property in source) { + if (typeof source[property] === "object" && source[property] !== null && destination[property]) { + clone(destination[property], source[property]); + } else { + destination[property] = source[property]; + } + } +}; + +function Xk_Yes() { + var F = document.getElementById('sta'); + var G = document.getElementById('end'); + F.onclick = sta; + G.onclick = end; +} + +function XK_No() { + document.getElementById("Outer").innerHTML = "
这个东西只能在选课系统里面用哦~
by 也爱你们的喵
"; + document.getElementById("Outer").style.removeProperty['width']; +} + +window.onload = function() { + chrome.tabs.getSelected(null, + function(tab) { + chrome.tabs.sendMessage(tab.id, { + "nil": "nil" + }, + function(response) { + try { + if (response[0] == "Started") fill(response[1]); + ChangeStatus(response[0]); + } catch(e) { + //maybe Nothing to do + } + console.log(response); + }); + }); + chrome.tabs.query({ + 'active': true, + 'lastFocusedWindow': true + }, + function(tabs) { + Par(tabs[0].url)[4] === "222.30.32.10" ? Xk_Yes() : XK_No(); + }); + +}; \ No newline at end of file diff --git a/js/popup.html b/js/popup.html new file mode 100644 index 0000000..1eb42c4 --- /dev/null +++ b/js/popup.html @@ -0,0 +1,32 @@ + + + + + + + +
+
选课序号1:
+ 选课序号2:
+ 选课序号3:
+ 选课序号4:
+
+ + +
+
+

选课机状态:Stopped

+
+
+ + \ No newline at end of file diff --git a/manifest.json b/manifest.json index 1a0ac2b..5803782 100644 --- a/manifest.json +++ b/manifest.json @@ -1,16 +1,23 @@ { "name": "南开选课系统补丁", - "version": "0.0.3", + "version": "0.0.4", "manifest_version": 2, - "description": "修复南开选课系统提示密码错误无法登录,以及登录后左侧边栏无法正常显示的问题", + "description": "修复南开选课系统提示密码错误无法登录,以及登录后左侧边栏无法正常显示的问题,抢课功能请慎重使用,以免水表不保", "permissions": [ - "http://222.30.32.10/*" + "http://222.30.32.10/*", + "", + "tabs" ], + "content_scripts": [ { - "matches": ["http://222.30.32.10/*"], + "matches": ["http://222.30.32.10/*", ""], "run_at": "document_idle", "js": ["js/patch.js"] } - ] + ], + "browser_action": { + "default_icon": "img/normal.png", + "default_popup": "js/popup.html" + } }