水墨图床妖火快捷上传插件

上传图片并一键插入BBCode图片代码

  1. // ==UserScript==
  2. // @name 水墨图床妖火快捷上传插件
  3. // @namespace https://img.ink/
  4. // @version 0.25
  5. // @description 上传图片并一键插入BBCode图片代码
  6. // @author You
  7. // @match *://yaohuo.me/*
  8. // @match *://*.yaohuo.me/*
  9. // @icon https://img.ink/favicon.ico
  10. // @run-at document-end
  11. // @grant none
  12. // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.6.4/jquery.js
  13. // @require https://cdn.staticfile.org/layui/2.8.2/layui.min.js
  14. // @require https://cdn.staticfile.org/layer/3.5.1/layer.min.js
  15. // ==/UserScript==
  16.  
  17.  
  18.  
  19. var token = ''; //这里输入你的token,如果希望以游客身份上传,请留空。
  20. //token获取方式:进入https://img.ink/user/settings.html,第四行即是token,复制粘贴到上方即可
  21. //示例: 原本的 '' 修改为 '25d9e338dd539b8f5cb222d8e662be5d'
  22. //即在''中添加即可
  23.  
  24.  
  25.  
  26. (function() {
  27. 'use strict';
  28. // 在<head>标签内插入layui CSS
  29. const layuiCssLink = '<link rel="stylesheet" href="https://cdn.staticfile.org/layui/2.8.2/css/layui.min.css"><link rel="stylesheet" href="https://cdn.staticfile.org/layer/3.5.1/mobile/need/layer.min.css">';
  30. // 在<head>标签内插入layui CSS
  31. $('link[href="/template/default/xqx.css"]').before(layuiCssLink);
  32.  
  33. $('head').append(layuiCssLink);
  34. // 添加样式
  35. const style = `
  36.  
  37. <style>
  38. body {
  39. font: inherit !important;
  40. line-height: 32px !important;
  41. margin: 0 auto;
  42. }
  43. .container {
  44. display: flex;
  45. }
  46.  
  47. .textarea-container {
  48. width: 70%;
  49. }
  50.  
  51. .upload-container {
  52. width: 30%;
  53. display: flex;
  54. align-items: center; // 垂直居中
  55. justify-content: center; // 水平居中
  56. }
  57.  
  58. .layui-upload-drag {
  59. height: 80px;
  60. padding: 0;
  61. line-height: 1;
  62. }
  63.  
  64. .textarea-container textarea {
  65. width: 100%;
  66. }
  67. a {
  68. color: #3d68a8 !important;
  69. text-decoration: none !important;
  70. font-size: 17px !important;
  71. }
  72. div.justify5213 {
  73. letter-spacing: .7px;
  74. overflow: hidden;
  75. height: 31px;
  76. padding: 5px 0 0 5px;
  77. }
  78. div.justify5213 > span {
  79. display: inline-block;
  80. padding-left: 100%;
  81. }
  82. a.topic-link:visited, div.list a:visited {
  83. color: #A3A3A3 !important;
  84. }
  85. .border-solid img {
  86. border: 1px solid #d3d3d3 !important;
  87. }
  88. .border-solid2 img {
  89. border: 2px solid #d3d3d3 !important;
  90. max-width: 99% !important;
  91. }
  92. .listdata img {
  93. padding-right: 0.1em !important;
  94. }
  95. .number {
  96. line-break: auto !important;
  97. }
  98. @font-face {
  99. font-family: "LxgwWenKai";
  100. font-display: swap;
  101. src: url(./css/font/LXGWWenKai5.ttf);
  102. }
  103. .LXGW {
  104. text-align: center;
  105. font: 21px/2.2 'LxgwWenKai';
  106. font-weight: 700;
  107. }
  108. .LxgwWenKai {
  109. font-family: "LxgwWenKai" !important;
  110. }
  111. </style>
  112. `;
  113.  
  114. // 添加拖拽上传HTML
  115. const uploadHtml = `
  116. <div class="upload-container">
  117. <div class="layui-upload-drag" id="uploadDrag">
  118. <i class="layui-icon"></i>
  119. <p>点击上传,或将图片拖拽到此处</p>
  120. </div>
  121. </div>
  122.  
  123. `;
  124. // 调整输入框高度
  125. const uploadContainerHeight = $('.upload-container .layui-upload-drag').outerHeight();
  126. $('.textarea-container textarea').css('height', uploadContainerHeight + 'px');
  127.  
  128. $('head').append(style);
  129. $('.retextarea').wrap('<div class="container"></div>');
  130. $('.retextarea').wrap('<div class="textarea-container"></div>');
  131. $(uploadHtml).insertAfter('.textarea-container');
  132. const creditText = `
  133. <div style="font-size: 9px; color: #888; text-align: center; margin-top: 8px;">
  134. 图片上传接口由
  135. <a href="https://img.ink/" target="_blank" style="font-weight: bold; color: #888;">
  136. 水墨图床
  137. </a>
  138. 提供
  139. </div>
  140. `;
  141. $('.container').after(creditText);
  142. const layer = layui.layer;
  143. layui.use('upload', function () {
  144. var upload = layui.upload;
  145. var element = layui.element;
  146. upload.render({
  147. elem: '#uploadDrag',
  148. url: 'https://img.ink/api/upload',
  149. accept: 'images',
  150. acceptMime: '.jpg,.jpeg,.gif,.png,.ico,.bmp',
  151. multiple: true,
  152. field: ['image'],
  153. exts: 'jpg|jpeg|gif|png|ico|bmp',
  154. headers: token ? {'token': token} : {},
  155. done: function (res) {
  156. if (res.code === 200) {
  157. const bbcode = `[img]${res.data.url}[/img]\n`;
  158. const $textarea = $('textarea[name="content"]');
  159. $textarea.val($textarea.val() + bbcode);
  160. } else {
  161. layer.msg('上传失败:' + res.msg);
  162. }
  163. },
  164. error: function () {
  165. layer.msg('上传失败');
  166. },
  167. });
  168. });
  169. })();
  170. (function() {
  171. 'use strict';
  172. $(document).ready(function() {
  173. // 调整输入框高度
  174. setTimeout(function() {
  175. const uploadContainerHeight = $('.upload-container .layui-upload-drag').outerHeight();
  176. $('.textarea-container textarea').css('height', uploadContainerHeight + 'px');
  177. $('.textarea-container textarea').css('width', '100%');
  178. }, 500);
  179. });
  180. })();

QingJ © 2025

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