「Z-Blog」前台编辑文章入口

配合主题以显示前台编辑入口

安裝腳本?
作者推薦腳本

您可能也會喜歡 「Z-Blog」开发者工具(本地)

安裝腳本
  1. // ==UserScript==
  2. // @name 「Z-Blog」前台编辑文章入口
  3. // @namespace https://www.wdssmq.com/
  4. // @version 1.0.3
  5. // @author 沉冰浮水
  6. // @description 配合主题以显示前台编辑入口
  7. // @license MIT
  8. // @null ----------------------------
  9. // @contributionURL https://github.com/wdssmq#%E4%BA%8C%E7%BB%B4%E7%A0%81
  10. // @contributionAmount 5.93
  11. // @null ----------------------------
  12. // @link https://github.com/wdssmq/userscript
  13. // @link https://afdian.net/@wdssmq
  14. // @link https://gf.qytechs.cn/zh-CN/users/6865-wdssmq
  15. // @null ----------------------------
  16. // @noframes
  17. // @run-at document-end
  18. // @match *://*/post/*.html*
  19. // @match *://*/*.html
  20. // @match *://*/zb_system/admin/edit.php*
  21. // @grant none
  22. // ==/UserScript==
  23.  
  24. /* eslint-disable */
  25. /* jshint esversion: 6 */
  26.  
  27. (function () {
  28. 'use strict';
  29.  
  30. // 初始常量或函数
  31. const curUrl = window.location.href;
  32. // ---------------------------------------------------
  33. const $ = window.$ || unsafeWindow.$;
  34.  
  35. function _mdToc () {
  36. const postTitle = $(".post-title");
  37. const $$referenceLink = $(".reference-link");
  38. // console.log("$$referenceLink = ", $$referenceLink);
  39.  
  40. const _setAnchorLink = (el, $refLink) => {
  41. const anchorId = el.attr("id");
  42. const title = $refLink.attr("name");
  43. // 锚点链接目标
  44. const arrHash = [
  45. `#${anchorId}`,
  46. `#${title}`,
  47. ];
  48.  
  49. const $a = $("<a>")
  50. .attr("href", "#")
  51. .attr("title", title)
  52. .html("#")
  53. .addClass("header-anchor")
  54. .data("hash", arrHash[0])
  55. .css({
  56. borderBottom: "none",
  57. marginRight: "3px",
  58. marginLeft: "-11px",
  59. visibility: "hidden",
  60. })
  61. .click(() => {
  62. // 根据 data-hash 属性,切换锚点链接目标
  63. const hash = $a.data("hash");
  64. const newHash = arrHash.filter(item => item !== hash)[0];
  65. $a.attr("href", newHash);
  66. $a.data("hash", newHash);
  67. document.title = `${title} - ${postTitle.text()}`;
  68. });
  69. const $span = el.find(".header-link");
  70.  
  71. $span.replaceWith($a);
  72.  
  73. // // 移除 el 直接的文本节点,但是保留 el 的子节点
  74. // el.contents().filter(function () {
  75. // return this.nodeType === 3;
  76. // }).remove();
  77. };
  78.  
  79. // 遍历
  80. $$referenceLink.each(function (el) {
  81. const $anchor = $(this).parent();
  82. const _this = $(this);
  83. _setAnchorLink($anchor, _this);
  84. // 绑定鼠标 hover 事件
  85. $anchor.hover(function () {
  86. $anchor.find(".header-anchor").css({
  87. visibility: "visible",
  88. marginLeft: "-5px",
  89. });
  90. }, function () {
  91. $anchor.find(".header-anchor").css({
  92. visibility: "hidden",
  93. marginLeft: "-11px",
  94. });
  95. });
  96. });
  97.  
  98. }
  99.  
  100. $(function () {
  101. _mdToc();
  102. // 添加编辑按钮
  103. $(".js-edt")
  104. .each(function () {
  105. const id = $(this).data("id");
  106. const type = $(this).data("type");
  107. const act = type ? "PageEdt" : "ArticleEdt";
  108. $(this).html(
  109. `[<a title="编辑" rel="external" href="${window.bloghost}zb_system/cmd.php?act=${act}&id=${id}">编辑</a>]`,
  110. );
  111. })
  112. .removeClass("is-hidden hidden");
  113.  
  114. // 清理评论失效网址
  115. $(".cmt-tips").each(function () {
  116. const $this = $(this);
  117. const authName = $this.data("name");
  118. $this.append(
  119. ` <a class="cmt-edit" title="查找编辑" rel="external" href="${window.bloghost}zb_users/plugin/cmt2rss/main.php?act=update&read_getWord=${authName}" target="_blank">查找编辑</a>`,
  120. );
  121. });
  122. $(".cmt-edit").css({ color: "#175199" });
  123.  
  124. // 设置文章为回收
  125. if (curUrl.indexOf("zblogcn.com") > -1) {
  126. return;
  127. }
  128. $("#edtTitle").after(
  129. "<a class=\"js-empty\" href=\"javascript:;\" title=\"设置为回收\"> 「设置为回收」</a>",
  130. );
  131. let editor_api = window.editor_api;
  132. $(".js-empty").click(function () {
  133. $("#edtTitle").val("回收");
  134. $("#edtTag").val("回收");
  135. $("#edtDateTime").datetimepicker("setDate", (new Date()));
  136. $("#cmbPostStatus").val("1");
  137. let strMore = "";
  138. if (typeof window.EDITORMD == "object") {
  139. strMore = "\n\n<!--more-->";
  140. } else {
  141. strMore = "<hr class=\"more\" />";
  142. }
  143. let oBody = "回收" + strMore;
  144. editor_api.editor.content.put(oBody);
  145. editor_api.editor.intro.put("");
  146. });
  147. });
  148.  
  149. })();

QingJ © 2025

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