Greasy Fork镜像 支持简体中文。

cms backend management

cms内部管理

  1. /*
  2. * @Description: File Description
  3. * @FilePath: /backend_cms_mangement/index.js
  4. * @LastEditors: zzz
  5. * @LastEditTime: 2022-04-14 15:11:54
  6. */
  7. // ==UserScript==
  8. // @name cms backend management
  9. // @name:zh-CN cms内部管理
  10. // @namespace http://tampermonkey.net/
  11. // @version 0.5.3
  12. // @description cms内部管理
  13. // @author zzailianlian
  14. // @require https://code.jquery.com/jquery-3.5.1.min.js
  15. // @match http://backend.meitun-test.com/index
  16. // @icon https://www.google.com/s2/favicons?sz=64&domain=meitun-test.com
  17. // @license MIT
  18. // @run-at document-idle
  19. // @grant GM_setValue
  20. // @grant GM_getValue
  21. // @grant GM_addElement
  22. // ==/UserScript==
  23.  
  24. (function () {
  25. 'use strict';
  26.  
  27.  
  28. var sc = document.createElement("script");
  29. sc.setAttribute("type", "text/javascript");
  30. sc.src = "https://code.jquery.com/jquery-3.5.1.min.js";
  31. // document.getElementsByTagName('body')[0].appendChild(sc);
  32.  
  33. if (window.ActiveXObject || "ActiveXObject" in window) { //判断是否是ie
  34. if (sc.readyState) { //判断是否支持readyState
  35. sc.onreadystatechange = function () {
  36. if (this.readyState == "loaded" || this.readyState == "complete") {
  37. console.log("ie10及以下加载完成");
  38. onloaded()
  39. }
  40. }
  41. } else {
  42. sc.onload = function () {
  43. console.log("ie11及Edge加载完成");
  44. onloaded()
  45. }
  46. }
  47. } else { //不是ie
  48. sc.onload = function () {
  49. console.log('非ie浏览器加载完成');
  50. onloaded()
  51. }
  52. }
  53.  
  54. function clearActivitedTab() {
  55. if ($('#menubar_tabs span[title="关闭"]').length) {
  56. $.map($('#menubar_tabs span[title="关闭"]'), function (item) {
  57. item.click()
  58. })
  59. }
  60. }
  61.  
  62. var onloaded = function () {
  63. var jqVersion = $.fn.property || $().property || jQuery.fn.jquery
  64. console.log('version版本:', jqVersion)
  65.  
  66. const wrapperToolsContainer = $('<div id="wrapperToolsContainer">更新的页面id:<input type="number" style="margin-bottom:8px;"/></div>')
  67.  
  68. wrapperToolsContainer.find('input').attr('value','783')
  69.  
  70. wrapperToolsContainer.css({
  71. position: 'fixed',
  72. top: 50,
  73. right: 100,
  74. padding: '12px',
  75. background: '#3498db',
  76. borderRadius: '4px',
  77. fontSize: '14px',
  78. zIndex: 999,
  79. opacity: 0.1,
  80. });
  81. wrapperToolsContainer.hover(function () { $(this).css({ opacity: 1 }); }, function () { $(this).css({ opacity: .1 }); })
  82. const initCMSModule = $('<div>初始化cms页面</div>')
  83. initCMSModule.css({
  84. padding: '12px',
  85. color: 'white',
  86. background: '#2ecc71',
  87. borderRadius: '4px',
  88. fontSize: '14px',
  89. border: '1px solid #27ae60',
  90. zIndex: 999,
  91. marginBottom: '24px',
  92. cursor: 'pointer'
  93. });
  94.  
  95. const syncConfig = $('<div>同步配置到页面</div>')
  96. syncConfig.css({
  97. padding: '12px',
  98. color: 'white',
  99. background: '#2ecc71',
  100. borderRadius: '4px',
  101. fontSize: '14px',
  102. border: '1px solid #27ae60',
  103. zIndex: 999,
  104. cursor: 'pointer'
  105.  
  106. });
  107.  
  108. wrapperToolsContainer.append(initCMSModule).append(syncConfig)
  109. $('body').append(wrapperToolsContainer)
  110.  
  111. const CMS_PAGE_TAB_ID = 'CMS_PAGE_TAB_ID'
  112. const CMS_MODULE_TAB_ID = 'CMS_MODULE_TAB_ID'
  113. function getLastTabId() {
  114. return $('#menubar_tabs').find('h3').last().find('a').attr('id')
  115. }
  116. initCMSModule.on('click', () => {
  117. clearActivitedTab();
  118. // 初始化cms管理tab
  119. $("a:contains('v2.0CMS页面管理')").get(0).click()
  120. GM_setValue(CMS_PAGE_TAB_ID, getLastTabId());
  121. $("a:contains('v2.0CMS系统模板')").get(0).click()
  122. GM_setValue(CMS_MODULE_TAB_ID, getLastTabId());
  123. })
  124.  
  125. function getFrameJQ(id) {
  126. // mainIframe_modifyPage
  127. // mainIframe_tabli_
  128. return $(document.getElementById(id).contentWindow.document.body)
  129. }
  130. function getIdFromTab(tabidArr) {
  131. if (!tabidArr || tabidArr instanceof Array) {
  132. return ''
  133. }
  134. return tabidArr.split('_').slice(-1) || ''
  135. }
  136. function loop(judgeFn = () => { }, callbackFn = () => { }, delay = 1000) {
  137. let threshold = 10 * delay; // 10个delay的时间,默认为10s
  138. console.log("interval start")
  139. let startTimeStamp = 0;
  140. const intervalTimer = window.setInterval(function () {
  141. console.log("interval running")
  142. startTimeStamp += delay;
  143. if (judgeFn()) {
  144. console.log("interval end")
  145. callbackFn()
  146. window.clearInterval(intervalTimer)
  147. return;
  148. }
  149. if (startTimeStamp >= threshold) {
  150. window.clearInterval(intervalTimer)
  151. console.error('loop超时')
  152. return new Error('loop超时')
  153. }
  154. }, delay)
  155. }
  156.  
  157.  
  158.  
  159. syncConfig.on('click', () => {
  160. const MODULE_ID = $('#wrapperToolsContainer').find('input').get(0).value;
  161.  
  162. if(!MODULE_ID){
  163. return alert('请输入要更新的页面id')
  164. }
  165. console.log('MODULE_ID',MODULE_ID)
  166.  
  167. // 同步配置模板到页面
  168. const pendingSyncList = $('button:contains("同步线上")')
  169. console.log('我是同步列表', pendingSyncList, window.performance)
  170. const cmsPageFrameJq = getFrameJQ('mainIframe_tabli_' + getIdFromTab(GM_getValue(CMS_PAGE_TAB_ID)))
  171. // 编辑页面
  172. cmsPageFrameJq.find('tr').find('td:contains(' + MODULE_ID + ')').parent().find('button:contains("编辑")').click()
  173.  
  174. loop(function () {
  175. return !!$('#mainIframe_modifyPage' + MODULE_ID).length
  176. }, function () {
  177. // 存在该iframe说明已经【编辑点击之后调起iframe】
  178. const cmsPageModalFrameJq = getFrameJQ('mainIframe_modifyPage' + MODULE_ID)
  179. loop(function () {
  180. // 副标题存在数据,说明【编辑操作】掉接口回填成功
  181. return !!$(getFrameJQ('mainIframe_modifyPage' + MODULE_ID)).find('input[placeholder="如:APP新客活动"]').last().attr('value')
  182. }, function () {
  183. // 下一步
  184. $(getFrameJQ('mainIframe_modifyPage' + MODULE_ID)).find('input[value="下一步"]').last().click();
  185. loop(function () {
  186. // 如果模拟器中存在模板数据,说明【下一步操作】掉接口回填成功
  187. return !!$(getFrameJQ('mainIframe_modifyPage' + MODULE_ID)).find('.cms-show').length
  188. },
  189. function () {
  190. // 保存
  191. $(getFrameJQ('mainIframe_modifyPage' + MODULE_ID)).find('input[value="保存"]').last().click()
  192. loop(function () {
  193. // 如果存在同步线上按钮,说明【保存操作】掉接口回填成功
  194. return !!$(getFrameJQ('mainIframe_tabli_' + getIdFromTab(GM_getValue(CMS_PAGE_TAB_ID)))).find('tr').find('td:contains(' + MODULE_ID + ')').parent().find('button:contains("同步线上")').length
  195. }, function () {
  196. // 同步线上
  197. $(getFrameJQ('mainIframe_tabli_' + getIdFromTab(GM_getValue(CMS_PAGE_TAB_ID)))).find('tr').find('td:contains(' + MODULE_ID + ')').parent().find('button:contains("同步线上")').click()
  198. })
  199. })
  200. })
  201. })
  202. })
  203. }
  204. onloaded()
  205. })();

QingJ © 2025

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