PriateLib

自用

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/435476/1202493/PriateLib.js

  1. // ==UserScript==
  2. // @name PriateLib
  3. // @version 0.0.5
  4. // @description 自用
  5. // @author Priate
  6. // @grant GM_xmlhttpRequest
  7. // @include *
  8. // ==/UserScript==
  9.  
  10. // 睡眠多少秒
  11. async function Sleep(sleepSecs) {
  12. return new Promise((resolve, reject) => {
  13. setTimeout(() => {
  14. resolve()
  15. }, sleepSecs * 1000)
  16. })
  17. }
  18.  
  19. // 等待某个函数执行完毕(每多少秒检测一次)
  20. async function WaitUntil(conditionFunc, sleepSecs) {
  21. sleepSecs = sleepSecs || 1
  22. return new Promise((resolve, reject) => {
  23. if (conditionFunc()) resolve()
  24. let interval = setInterval(() => {
  25. if (conditionFunc()) {
  26. clearInterval(interval)
  27. resolve()
  28. }
  29. }, sleepSecs * 1000)
  30. })
  31. }
  32.  
  33. // GM_xmlhttpRequest 简单封装
  34. function Request(url, opt = {}) {
  35. Object.assign(opt, {
  36. url,
  37. timeout: 2000,
  38. responseType: 'json'
  39. })
  40.  
  41. return new Promise((resolve, reject) => {
  42. opt.onerror = opt.ontimeout = reject
  43. opt.onload = resolve
  44. GM_xmlhttpRequest(opt)
  45. }).then(res => {
  46. if (res.status === 200) return Promise.resolve(res.response)
  47. else return Promise.reject(res)
  48. }, err => {
  49. return Promise.reject(err)
  50. })
  51. }
  52.  
  53. // easy http(s) get
  54. function Get(url, opt = {}) {
  55. Object.assign(opt, {
  56. method: 'GET'
  57. })
  58. return Request(url, opt)
  59. }
  60.  
  61. // easy http(s) post
  62. function Post(url, opt = {}) {
  63. Object.assign(opt, {
  64. method: 'POST'
  65. })
  66. return Request(url, opt)
  67. }
  68.  
  69. // simple toast
  70. function showToast(msg, doNotFade) {
  71. let style = `position: fixed; right: 10px; top: 80px; width: 300px; text-align: left; background-color: rgba(255, 255, 255, 0.9); z-index: 99; padding: 10px 20px; border-radius: 5px; color: #222; box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.2); font-weight: bold;`
  72.  
  73. let span = document.createElement('span')
  74. span.setAttribute('style', style)
  75. span.innerText = msg
  76. document.body.appendChild(span)
  77. if (!doNotFade) {
  78. setTimeout(() => {
  79. document.body.removeChild(span)
  80. }, 5000)
  81. }
  82. }
  83.  
  84. async function GetElementByText(startElem, selector, text, exist) {
  85. /*
  86. selector: 选择器
  87. text: 内容
  88. exist: 是否只要存在就ojbk
  89. */
  90. exist = exist || false
  91. let elemList = startElem.querySelectorAll(selector)
  92. for (let i = 0; i < elemList.length; ++i) {
  93. let elem = elemList[i]
  94. if (exist) {
  95. if (elem.innerText.search(text) !== -1) return elem
  96. } else {
  97. if (elem.innerText === text) return elem
  98. }
  99. }
  100. }
  101. /**
  102. * 替换全部匹配到的内容
  103. * @param FindText 需要查找的字符串
  104. * @param RepText 将要替换的字符串
  105. * @returns {string}
  106. */
  107. String.prototype.replaceAll = function(FindText, RepText) {
  108. let regExp = new RegExp(FindText, "g");
  109. return this.replace(regExp, RepText);
  110. }
  111.  
  112. /**
  113. * 移除iframe页面元素,用于wifi劫持和去除iframe广告
  114. */
  115. function removeIframe() {
  116. let filter = new Object();
  117. filter.ad = function() {
  118. let tar = document.getElementsByTagName('iframe');
  119. let len = tar.length;
  120. if (len > 0) {
  121. for (let i = 0; i < len; i++) {
  122. tar[0].remove()
  123. }
  124. }
  125. }
  126. filter.timer = function() {
  127. let clean = setInterval(function() {
  128. if (document.getElementsByTagName('iframe').length == 0) {
  129. clearInterval(clean)
  130. console.log('清除')
  131. } else {
  132. filter.ad()
  133. }
  134. }, 300)
  135. }
  136. filter.timer()
  137. }
  138. /**
  139. * 向页面中添加div
  140. * @param className 类名
  141. * @param innerHtml 内容
  142. * @param clickFunc 点击事件函数
  143. * @returns {HTMLDivElement}
  144. */
  145. function loadDiv(className = '', innerHtml = '', clickFunc = false) {
  146. let div = document.createElement('div')
  147. div.className = className
  148. div.innerHTML = innerHtml
  149. if (typeof clickFunc == 'function') {
  150. div.onclick = clickFunc
  151. }
  152. document.body.append(div)
  153. return div
  154. }
  155. /**
  156. * 加载js文件
  157. * @param url js文件路径
  158. * @param callback 加载成功后执行的回调函数
  159. */
  160. function loadJs(url, callback) {
  161. let head = document.getElementsByTagName('head')[0];
  162. let script = document.createElement('script');
  163. script.type = 'text/javascript';
  164. script.src = url;
  165. if (typeof(callback) == 'function') {
  166. script.onload = script.onreadystatechange = function() {
  167. if (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") {
  168. callback();
  169. script.onload = script.onreadystatechange = null;
  170. }
  171. };
  172. }
  173. head.appendChild(script);
  174. }
  175. /**
  176. * 获取当前URL地址参数
  177. * @param name 参数名称
  178. * @returns {string|null}
  179. */
  180. function getUrlParam(name) {
  181. let reg = new RegExp("(.|&)" + name + "=([^&]*)(&|$)");
  182. let r = window.location.href.match(reg);
  183. if (r != null) return unescape(r[2]);
  184. return null;
  185. }
  186. /**
  187. * 执行函数
  188. * @param func 函数
  189. * @param time 延时,负数:延时->执行,正数:执行->延时
  190. * @param desc
  191. * @returns {Promise<unknown>}
  192. */
  193. function obsFunc(func, time = 0, desc = 'func') {
  194. return new Promise(resolve => {
  195. if (!!func) {
  196. if (time < 0) {
  197. setTimeout(() => {
  198. func()
  199. console.log(desc)
  200. resolve('func')
  201. }, Math.abs(time) * 1000)
  202. } else if (time > 0) {
  203. func()
  204. setTimeout(() => {
  205. console.log(desc)
  206. resolve('func')
  207. }, Math.abs(time) * 1000)
  208. } else {
  209. func()
  210. console.log(desc)
  211. resolve('func')
  212. }
  213. }
  214. })
  215. }
  216.  
  217.  
  218. /**
  219. * 懒加载某元素
  220. * @param el 元素选择器(字符串)
  221. * @param func 回调函数
  222. * @param times 次数
  223. * @param interval 间隔时间
  224. */
  225. function loadElement(el, func, times, interval) {
  226. var _times = times || 100, //100次
  227. _interval = interval || 200, //200毫秒每次
  228. _self = document.querySelector(el),
  229. _iIntervalID; //定时器id
  230. if (_self) { //如果已经获取到了,就直接执行函数
  231. func && func.call(el);
  232. } else {
  233. _iIntervalID = setInterval(function() {
  234. if (!_times) { //是0就退出
  235. clearInterval(_iIntervalID);
  236. }
  237. _times <= 0 || _times--; //如果是正数就 --
  238. _self = document.querySelector(el); //再次选择
  239. if (_self) { //判断是否取到
  240. func && func.call(el);
  241. clearInterval(_iIntervalID);
  242. }
  243. }, _interval);
  244. }
  245. return this;
  246. }
  247.  
  248.  
  249. /**
  250. * 获取当前时间字符串
  251. */
  252. function getNowFormatDate() {
  253. var date = new Date();
  254. var seperator1 = "-";
  255. var seperator2 = ":";
  256. var month = date.getMonth() + 1;
  257. var strDate = date.getDate();
  258. if (month >= 1 && month <= 9) {
  259. month = "0" + month;
  260. }
  261. if (strDate >= 0 && strDate <= 9) {
  262. strDate = "0" + strDate;
  263. }
  264. var currentdate = month + seperator1 + strDate + " " + date.getHours() + seperator2 + date.getMinutes()
  265. return currentdate;
  266. }
  267.  
  268. /**
  269. * Aria2下载
  270. * @param url 下载文件地址
  271. * @param filename 下载文件名(带后缀)
  272. * @param config 下载配置
  273. */
  274. function Aria2(url, filename, config = {
  275. wsurl: "ws://127.0.0.1:6800/jsonrpc",
  276. token: ""
  277. }) {
  278. var wsurl = config.wsurl
  279. var token = config.token
  280. var uris = [url]
  281. var options = {
  282. "max-connection-per-server": "16",
  283. "user-agent": "Opera\/9.80 (Windows NT 6.0) Presto\/2.12.388 Version\/12.14",
  284. }
  285. if (filename != "") {
  286. options.out = filename;
  287. }
  288.  
  289. let json = {
  290. "id": "priate-script",
  291. "jsonrpc": '2.0',
  292. "method": 'aria2.addUri',
  293. "params": [uris, options],
  294. };
  295.  
  296. if (token != "") {
  297. json.params.unshift("token:" + token);
  298. }
  299. var ws = new WebSocket(wsurl);
  300.  
  301. ws.onerror = event => {
  302. console.log(event);
  303. };
  304. ws.onopen = () => {
  305. ws.send(JSON.stringify(json));
  306. }
  307.  
  308. ws.onmessage = event => {
  309. console.log(event);
  310. let received_msg = JSON.parse(event.data);
  311. if (received_msg.error !== undefined) {
  312. if (received_msg.error.code === 1)
  313. console.log(received_msg.error.message)
  314. }
  315. switch (received_msg.method) {
  316. case "aria2.onDownloadStart":
  317. console.log('Aria2 已经开始下载!' + filename)
  318. break;
  319. case "aria2.onDownloadError":
  320. ;
  321. console.log('Aria2 下载错误!');
  322. break;
  323. case "aria2.onDownloadComplete":
  324. console.log('Aria2 下载完成!');
  325. break;
  326. default:
  327. break;
  328. }
  329. };
  330. }
  331.  
  332.  
  333. /**
  334. * 显示赞赏图片
  335. */
  336. async function showDonate() {
  337. function isChinese(temp) {
  338. var re = /[^\u4E00-\u9FA5]/;
  339. if (re.test(temp)) return false;
  340. return true;
  341. }
  342. async function autoWord(selector, wordStr) {
  343. const dom = document.querySelector(selector);
  344. for (var a in wordStr) {
  345. dom.innerHTML = wordStr.substr(0, a)
  346. if (isChinese(wordStr.charAt(a))) await Sleep(0.1)
  347. }
  348. await Sleep(1)
  349. }
  350. var priate_donate_script_div = document.createElement("div")
  351. priate_donate_script_div.innerHTML = `
  352. <div id="priate_donate_script_div">
  353. <p class="priate_donate_script_p"><a href="https://donate.virts.app/" target="_blank"><img class="priate_donate_script_img" src="https://priate.oss-cn-beijing.aliyuncs.com/products/picture/all.jpg"></a></p>
  354. <p class="priate_donate_script_text first"></p>
  355. <p class="priate_donate_script_text second"></p>
  356. <p class="priate_donate_script_text third"></p>
  357. <p class="priate_donate_script_text fourth"></p>
  358. <br>
  359. <p class="priate_donate_script_text"><a id="exitDonate" style="display:none;" class="hover-underline-animation a-pink"></a></p>
  360. </div>
  361. `
  362. GM_addStyle(`
  363. #priate_donate_script_div{
  364. height : 100%;
  365. width : 100%;
  366. position : fixed;
  367. z-index : 2147483647;
  368. top : 0;
  369. font-weight : 100;
  370. background-color: rgb(254,215,224);
  371. }
  372. .priate_donate_script_p{
  373. text-align : center;
  374. margin : 40px auto;
  375. }
  376. .priate_donate_script_img{
  377. cursor : pointer;
  378. width : 500px;
  379. }
  380. .priate_donate_script_text{
  381. text-align : center;
  382. font-size: 20px;
  383. color: #660000;
  384. margin-bottom : 0 !important;
  385. margin-top : 5px !important;
  386. }
  387. .hover-underline-animation {
  388. display: inline-block;
  389. position: relative;
  390. text-decoration: none;
  391. cursor: pointer;
  392. }
  393. .hover-underline-animation:after {
  394. content: '';
  395. position: absolute;
  396. width: 100%;
  397. transform: scaleX(0);
  398. height: 1px;
  399. bottom: 0;
  400. left: 0;
  401. /* background-color: #0087ca; */
  402. transform-origin: bottom right;
  403. transition: transform 0.25s ease-out;
  404. }
  405. .hover-underline-animation:hover:after {
  406. transform: scaleX(1);
  407. transform-origin: bottom left;
  408. }
  409. .a-purple{
  410. color: #946ce6 !important;
  411. }
  412. .a-purple:after{
  413. background-color: #946ce6;
  414. }
  415.  
  416. .a-blue{
  417. color: #1778FF !important;
  418. }
  419. .a-blue:after{
  420. background-color: #1778FF;
  421.  
  422. }.a-green{
  423. color: #05DF6D !important;
  424. }
  425. .a-green:after{
  426. background-color: #05DF6D;
  427. }
  428. .a-yellow{
  429. color: #FFD404 !important;
  430. }
  431. .a-yellow:after{
  432. background-color: #FFD404;
  433. }
  434. .a-pink{
  435. color: hsl(312, 100%, 69%) !important;
  436. }
  437. .a-pink:after{
  438. background-color: hsl(312, 100%, 69%);
  439. }
  440. `);
  441. document.querySelector("html").appendChild(priate_donate_script_div)
  442. document.querySelector("#exitDonate").addEventListener('mouseenter', function() {
  443. this.innerText = "谢谢您的支持~~~笔芯♥️♥️♥️♥️♥️♥️♥️♥️♥️"
  444. })
  445. document.querySelector("#exitDonate").addEventListener('click', function() {
  446. priate_donate_script_div.remove()
  447. })
  448.  
  449. await autoWord('.first', 'Hi ~ 这是我的个人赞赏页面,能打开这个页面就已经很感谢啦 🙏 ');
  450. await autoWord('.second', '如果您想支持我的创作可以扫描上面的二维码或者在 <a href="https://afdian.net/@cyberubbish" target="_blank" class="hover-underline-animation a-purple">爱发电</a> 进行打赏哦 ❤️ ');
  451. await autoWord('.third', '谢谢你这么好看还给我零花钱 😘 ');
  452. await autoWord('.fourth', '这是我的 👉 <a class="hover-underline-animation a-blue" target="_blank" href="https://github.com/PriateXYF">Github</a> 👈 地址,你可以 Follow 我了解我的最新动态~ ');
  453. document.querySelector("#exitDonate").style = ""
  454. await autoWord('#exitDonate', '谢谢你读到这里,点我就可以关闭此页面啦~ ');
  455. document.querySelector("#exitDonate").addEventListener('click', function() {
  456. priate_donate_script_div.remove()
  457. })
  458. priate_donate_script_div.addEventListener('click', function() {
  459. priate_donate_script_div.remove()
  460. })
  461. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址