mylib

我的工具

目前為 2021-12-17 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.cn-greasyfork.org/scripts/435697/999450/mylib.js

  1. function 添加样式(css,id='') {//植入css
  2. const style = document.createElement('style');
  3. style.type='text/css';
  4. id!=''?style.id = id:0;
  5. style.textContent = css;
  6. const h0 =document.querySelector('html');
  7. h0.insertBefore(style,h0.children[0]);
  8. }
  9. function seconds2date(seconds){//秒数转日期//getDateStr(1524637692)>"2018-4-25 14:28:12"
  10. var date = new Date(seconds*1000)
  11. var year = date.getFullYear();
  12. var month = date.getMonth() + 1;
  13. var day = date.getDate();
  14. var hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
  15. var minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
  16. var second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
  17. var currentTime = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
  18. return currentTime
  19. }
  20. /*HTMLElement.prototype.appendChilds=function(){//DOM对象的appendChilds方法:实现批量添加nodes
  21. const args = arguments;
  22. let documentFragment = document.createDocumentFragment();
  23. for(let i=0;i<args.length;i++){
  24. documentFragment.appendChild(args[i]);
  25. }
  26. this.appendChild(documentFragment);
  27. }*/
  28. //document.body.appendChilds(document.createElement('fuck'),document.createElement('suck'),document.createElement('crap'))
  29. //刚发现一坑:不能用这种方法调用这个函数,除非在油猴里使用。
  30. function 追加子元素(父亲,标签,内容) {//追加子元素(document.body,'标签','内容','idk','true','data-s')
  31. const 新元素 = document.createElement(标签)
  32. 新元素.appendChild(document.createTextNode(内容));
  33. const = arguments.length;
  34. if (长>3) {
  35. for(let i=3;i<长;i+=2){
  36. 新元素.setAttribute([arguments[i]],arguments[i+1])
  37. }
  38. }
  39. 父亲.appendChild(新元素);
  40. return 新元素;
  41. }
  42. function 追加兄弟元素(哥哥,标签,内容){//紧跟其后追加元素//追加兄弟元素(document.body,'div','','suck','1','dick')
  43. const 弟弟 = document.createElement(标签);
  44. 弟弟.appendChild(document.createTextNode(内容));
  45. const = arguments.length;
  46. if (长>3) {
  47. for(let i=3;i<长;i+=2){
  48. 弟弟.setAttribute([arguments[i]],arguments[i+1])
  49. }
  50. }
  51. return 哥哥.parentNode.insertBefore(弟弟,哥哥.nextElementSibling);
  52. }
  53. function fuckTiebaLogin(userName,password){//跳出登录框后再执行
  54. document.getElementById('TANGRAM__PSP_5__footerULoginBtn').click();
  55. document.getElementById('TANGRAM__PSP_5__userName').outerHTML+='';
  56. document.getElementById('TANGRAM__PSP_5__password').outerHTML+='';
  57. document.getElementById('TANGRAM__PSP_5__userName').value=userName;
  58. document.getElementById('TANGRAM__PSP_5__password').value=password;
  59. return document.getElementById('TANGRAM__PSP_5__submit').click();
  60. }
  61. function xb_getValue(aKey, aDefault) {
  62. 'use strict';
  63. let val = localStorage.getItem(__GM_STORAGE_PREFIX + aKey)
  64. if (null === val && 'undefined' != typeof aDefault) return aDefault;
  65. return val;
  66. }
  67. function xb_setValue(aKey, aVal) {
  68. 'use strict';
  69. localStorage.setItem(__GM_STORAGE_PREFIX + aKey, aVal);
  70. }
  71. function xb_deleteValue(aKey) {
  72. 'use strict';
  73. localStorage.removeItem(__GM_STORAGE_PREFIX + aKey);
  74. }