Caas-Helper

Caas Helper

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

  1. ; (function () {
  2.  
  3. window.caasHelper = {
  4. inited: false,
  5. init: function () {
  6. let _this = this
  7. if (_this.inited) return
  8. _this.inited = true
  9.  
  10. _this.load();
  11.  
  12. window.addEventListener('popstate', function (event) {
  13. _this.load();
  14. });
  15. },
  16. url: '',
  17. urlInfo: null,
  18. load: function () {
  19. if (this.url === window.location.href) return;
  20.  
  21. this.url = window.location.href
  22. this.urlInfo = sinHelper.Url.info(this.url)
  23.  
  24. let _callback = this.mapper[this.urlInfo.pathname] || null
  25. if (!_callback) {
  26. this.removeNode()
  27. return;
  28. }
  29.  
  30. this.render(true)
  31.  
  32. let _obj = _callback()
  33.  
  34. if (typeof _obj === "object" && _obj !== null) {
  35. if (!_obj.hasOwnProperty('no_xhr') || !_obj['no_xhr']) {
  36. sinHelper.Xhr.init()
  37. }
  38.  
  39. if (_obj.hasOwnProperty('init')) {
  40. _obj.init()
  41. }
  42. }
  43. },
  44. mapper: {},
  45. push: function (_key, _callback) {
  46. this.mapper[_key] = _callback;
  47. },
  48.  
  49. rendered: false,
  50. nodeId: '',
  51. headerClass: '',
  52. contentClass: '',
  53. buttonClass: '',
  54. randStr: function () {
  55. let _r = '';
  56. while (_r.length <= 0) { _r = Math.random().toString(36).slice(-8); }
  57. return _r;
  58. },
  59. initNodeSelector: function () {
  60. this.nodeId = 'caas_helper_container_1uFoY';
  61. if (!this.contentClass) {
  62. this.contentClass = 'caas_helper_content_' + this.randStr()
  63. }
  64. if (!this.headerClass) {
  65. this.headerClass = 'caas_helper_header_' + this.randStr()
  66. }
  67. if (!this.buttonClass) {
  68. this.buttonClass = 'caas_helper_button' + this.randStr()
  69. }
  70. },
  71. render: function (_force) {
  72. let _this = this
  73. if (_force) {
  74. this.rendered = false;
  75. this.removeNode()
  76. }
  77.  
  78. if (this.rendered) return
  79. this.rendered = true;
  80. this.initNodeSelector()
  81.  
  82. let style = `#${_this.nodeId}{position:fixed;right:16px;top:250px;display:inline-block;background:green;color:#fff;font-size:14px;line-height:30px;text-align:center;min-width:74px;min-height:30px;border-radius:16px;z-index:999999;}` +
  83. `#${_this.nodeId} .${_this.headerClass}{font-size:18px;font-weight:bold;cursor:pointer;user-select:none;padding:5px 16px;}` +
  84. `#${_this.nodeId} .${_this.contentClass}{text-align:left;max-height:501px;overflow-y:scroll;padding:0px 16px;scrollbar-width: none;-ms-overflow-style: none;}` +
  85. `#${_this.nodeId} .${_this.contentClass}::-webkit-scrollbar{display: none;}` +
  86. `#${_this.nodeId} .${_this.buttonClass}{cursor:pointer;user-select:none;width:100%; padding:5px 0px;text-align:center}` +
  87. '';
  88.  
  89. var _stylenode = document.createElement('style');
  90. _stylenode.setAttribute("type", "text/css");
  91. if (_stylenode.styleSheet) {// IE
  92. _stylenode.styleSheet.cssText = style;
  93. } else {// w3c
  94. var cssText = document.createTextNode(style);
  95. _stylenode.appendChild(cssText);
  96. }
  97. _stylenode.id = _this.nodeId + '_style'
  98.  
  99. var html = '' +
  100. ' <div class="' + _this.headerClass + '">\n' + '卡思助手' + ' </div>\n' +
  101. ' <div class="' + _this.contentClass + '">\n' + '' + '</div>\n' +
  102. '';
  103.  
  104. let _boxnode = document.createElement("div")
  105. _boxnode.id = _this.nodeId;
  106. _boxnode.innerHTML = html;
  107.  
  108. document.getElementsByTagName("body")[0].appendChild(_boxnode);
  109. document.body.appendChild(_stylenode);
  110.  
  111. this.getNodeHeader().onclick = function () {
  112. let _c = _this.getNodeContent()
  113. if (_c.style.display == 'none') {
  114. _this.showContent();
  115. } else {
  116. _this.hideContent();
  117. }
  118. }
  119. this.clearContent()
  120. },
  121. getNode: function () {
  122. return document.getElementById(this.nodeId)
  123. },
  124. getNodeHeader: function () {
  125. return this.getNode().getElementsByClassName(this.headerClass)[0];
  126. },
  127. getNodeContent: function () {
  128. return this.getNode().getElementsByClassName(this.contentClass)[0];
  129. },
  130. removeNode: function () {
  131. try {
  132. document.getElementById(this.nodeId).remove()
  133. } catch (e) { }
  134. try {
  135. document.getElementById(this.nodeId + '_style').remove()
  136. } catch (e) { }
  137. },
  138. clearContent: function () {
  139. this.setContent('')
  140. },
  141. hideContent: function () {
  142. this.getNodeContent().style.display = 'none';
  143. },
  144. showContent: function () {
  145. this.getNodeContent().style.display = '';
  146. },
  147. setContent: function (_src) {
  148. let _object = {};
  149. if (typeof _src === "object" && _src !== null) {
  150. _object = this.buildContent(_src)
  151. } else {
  152. _object = { 'html': _src }
  153. }
  154. if (!_object['html'] || _object['html'].length <= 0) this.hideContent()
  155.  
  156. this.getNodeContent().innerHTML = _object['html'];
  157.  
  158. (_object['callback'] || []).forEach(_func => {
  159. _func()
  160. })
  161.  
  162. this.showContent()
  163. },
  164. /* {"aaa": {title:'', html: '', callback: func, options:{}}, 'bbb': {}} */
  165. buildContent: function (_object) {
  166. let _html = "", _funcs = []
  167. for (let _k in _object) {
  168. let _obj = _object[_k]
  169. if (!_obj['html']) continue;
  170.  
  171. let _boxClass = `${this.contentClass}_item_box`, _titleClass = `${this.contentClass}_item_title`,
  172. _htmlClass = `${this.contentClass}_item_html`
  173. let _boxId = `${_boxClass}_${_k}`, _titleId = `${_titleClass}_${_k}`, _htmlId = `${_htmlClass}_${_k}`
  174.  
  175. _html += `<div class="${_boxClass}" id="${_boxId}">\n`
  176. if (_obj['title']) _html += `<div class="${_titleClass}" id="${_titleId}">${_obj['title']}</div>\n`
  177. _html += `<div class="${_htmlClass}" id="${_htmlId}">\n`
  178. _html += _obj['html'] + '\n'
  179. _html += `</div>\n</div>\n`
  180.  
  181. if (_obj['callback']) {
  182. if (typeof (_obj['callback']) == 'function') {
  183. _funcs.push(_obj['callback'])
  184. }
  185. if (Object.prototype.toString.call(_obj['callback']) === '[object Array]') {
  186. _obj['callback'].forEach(_call => {
  187. if (typeof (_call) == 'function') {
  188. _funcs.push(_call)
  189. }
  190. })
  191. }
  192. }
  193. if (_obj['options'] && _obj['options']['hide_item']) {
  194. _funcs.push(function () {
  195. let _domTitle = document.getElementById(_titleId), _domHtml = document.getElementById(_htmlId)
  196. _domTitle.innerHTML = '点击查看 - ' + _obj['title']
  197. _domTitle.style.cursor = 'pointer'
  198. _domHtml.style.display = 'none'
  199. _domTitle.onclick = function (_e) {
  200. if (_domHtml.style.display == 'none') {
  201. _domHtml.style.display = ''
  202. _domTitle.innerHTML = '点击收起 - ' + _obj['title']
  203. } else {
  204. _domHtml.style.display = 'none'
  205. _domTitle.innerHTML = '点击查看 - ' + _obj['title']
  206. }
  207. }
  208. })
  209. }
  210. }
  211. return {
  212. 'html': _html,
  213. 'callback': _funcs,
  214. }
  215. },
  216. buildButton: function (_text) {
  217. let btnId = this.nodeId + '_btn_' + new Date().getTime() + (function () { let _r = ''; while (_r.length <= 0) { _r = Math.random().toString(36).slice(-8); } return _r; }());
  218. let btnHtml = '<div id="' + btnId + '" class="' + this.buttonClass + '">' + _text + '</div>'
  219. return { btnId, btnHtml }
  220. },
  221. bindButtonEvent: function (_id, _function, _event) {
  222. if (!_event) _event = 'click'
  223. if (_event === 'click') {
  224. document.getElementById(_id).onclick = _function
  225. }
  226. },
  227. };
  228.  
  229. })();

QingJ © 2025

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