mylib

我的工具

目前为 2022-04-26 提交的版本。查看 最新版本

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

  1. //dependency:myDomAppendBro
  2. function myAddStyle(css,className=''){
  3. myDomAppendBro(document.body,'style',css,`type`,'text/css',`class`,className)
  4. }
  5. //enable or disable style with className
  6. function mySwitchStyle(...styleClassNames) {
  7. styleClassNames.forEach(e=>{
  8. const style=document.querySelector('style.'+e);
  9. !style.type?style.type="text/css":style.type=0
  10. })
  11. }
  12. //seconds2date(new Date().getTime())
  13. function seconds2date(seconds){
  14. const date=new Date(seconds),year=date.getFullYear(),month=date.getMonth()+1,day=date.getDate();
  15. const hour=date.getHours(),minute=date.getMinutes(),second=date.getSeconds(),milliseconds=date.getMilliseconds(),currentTime=year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second+":"+milliseconds;
  16. return currentTime
  17. }
  18. //myDocumentBodyAppendDom(document.body,'tag','content','idk','true','data-s')
  19. function myDomAppendSon(dom,tag,content) {
  20. const son = document.createElement(tag),len = arguments.length
  21. son.appendChild(document.createTextNode(content)),dom.appendChild(son);
  22. if (len>3) {
  23. for(let i=3;i<len;i+=2){
  24. son.setAttribute([arguments[i]],arguments[i+1])
  25. }
  26. }
  27. return son;
  28. }
  29. //myDomAppendBro(document.body,'div','','suck','1','dick')
  30. function myDomAppendBro(dom,tag,content){
  31. const bro = document.createElement(tag),len = arguments.length;
  32. bro.append(document.createTextNode(content)),dom.parentNode.insertBefore(bro,dom.nextElementSibling);
  33. if (len>3) {
  34. for(let i=3;i<len;i+=2){
  35. bro.setAttribute([arguments[i]],arguments[i+1])
  36. }
  37. }
  38. return bro;
  39. }
  40. //跳出登录框后再执行
  41. function myFuckTiebaLogin(userName,password){
  42. document.getElementById('TANGRAM__PSP_5__footerULoginBtn').click();
  43. document.getElementById('TANGRAM__PSP_5__userName').outerHTML+='';
  44. document.getElementById('TANGRAM__PSP_5__password').outerHTML+='';
  45. document.getElementById('TANGRAM__PSP_5__userName').value=userName;
  46. document.getElementById('TANGRAM__PSP_5__password').value=password;
  47. return document.getElementById('TANGRAM__PSP_5__submit').click();
  48. }
  49. function myXbGetValue(k, aDefault) {
  50. const val = localStorage.getItem("XB_"+k)
  51. if (!val && 'undefined' != typeof aDefault) return aDefault;
  52. return val;
  53. }
  54. //myXbSetValue('k', 'v')
  55. function myXbSetValue(k, v) {
  56. localStorage.setItem("XB_"+k, v);
  57. }
  58. //myXbSetValue('k')
  59. function myXbDeleteValue(k) {
  60. if(k.indexOf("XB_")!=-1) localStorage.removeItem(k);
  61. }
  62. function myXbListValues() {
  63. let list=[],j=0;
  64. for (let i=0; i<localStorage.length;i++) {
  65. let k=localStorage.key(i);
  66. if(k.indexOf("XB_")!=-1) list[j++] = localStorage.key(i);
  67. }return list;
  68. }
  69. //dependency:myXbListValues
  70. function myXbClearValues() {
  71. myXbListValues().forEach(e=>{
  72. localStorage.removeItem(e)
  73. })
  74. }
  75. //get len of json obj
  76. function myGetJsonLen(jsonObj){
  77. let jsonLen=0, key;
  78. for (key in jsonObj) {
  79. if (jsonObj.hasOwnProperty(key)) jsonLen++;
  80. }return jsonLen;
  81. }
  82. //syn console.log
  83. function myLog(text){
  84. console.log(JSON.stringify(text))
  85. }
  86. //dependency:myAddStyle,myDomAppendSon
  87. //myAddBtns(()=>{},a=e=>{confirm(e.target.id)},function(e){prompt(e.target.outerHTML)},function test(e){return 1})
  88. function myAddBtns(...funcs){
  89. funcs.forEach(e=>{
  90. if(typeof e !='function') return console.log(e);
  91. });
  92. let myDiv=document.querySelector('#myBtnContainerDiv'),btns=[];
  93. if(!myDiv) myDiv=myDomAppendSon(document.body,'div','','id','myBtnContainerDiv');
  94. myAddStyle(`#myBtnContainerDiv{z-index:1650729359811!important;position: fixed!important;right:0!important;top:0!important}`);
  95. for(let i=0;i<funcs.length;i++){
  96. let fname=funcs[i].name;
  97. if(!fname) fname="noname";
  98. const btn = myDomAppendSon(myDiv,'input','','value',fname,'type','button','class','myQuickBtn');
  99. btn.addEventListener('click',funcs[i]),btns[i]=btn;
  100. }return btns
  101. }
  102. //prevent document.title from being changed
  103. function myFixTitle(){
  104. Object.defineProperty(document,"title",{
  105. writable:false
  106. });
  107. }