NodeSeek自动上传图片到微信api并插入md链接

用的是ns大佬发的api接口

  1. // ==UserScript==
  2. // @name NodeSeek自动上传图片到微信api并插入md链接
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.2.1
  5. // @description 用的是ns大佬发的api接口
  6. // @author kingis和GPT
  7. // @match https://www.nodeseek.com/*
  8. // @license MIT
  9. // @grant GM_xmlhttpRequest
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. document.addEventListener('paste', function(event) {
  16. handlePaste(event);
  17. });
  18.  
  19. function handlePaste(event) {
  20. var items = (event.clipboardData || event.originalEvent.clipboardData).items;
  21. var imageFiles = [];
  22.  
  23. for (var i = 0; i < items.length; i++) {
  24. if (items[i].kind === 'file' && items[i].type.indexOf('image/') !== -1) {
  25. var blob = items[i].getAsFile();
  26. imageFiles.push(blob);
  27. }
  28. }
  29.  
  30. if (imageFiles.length > 0) {
  31. event.preventDefault();
  32. for (var j = 0; j < imageFiles.length; j++) {
  33. var formData = new FormData();
  34. formData.append('media', imageFiles[j]);
  35. uploadToImageHost(formData);
  36. }
  37. }
  38. }
  39.  
  40. function uploadToImageHost(formData) {
  41. GM_xmlhttpRequest({
  42. method: 'POST',
  43. url: 'https://openai.weixin.qq.com/weixinh5/webapp/h774yvzC2xlB4bIgGfX2stc4kvC85J/cos/upload',
  44. data: formData,
  45. onload: function(response) {
  46. var jsonResponse = JSON.parse(response.responseText);
  47. if (response.status === 200 && jsonResponse && jsonResponse.url) {
  48. insertToEditor('![image](' + jsonResponse.url + ')');
  49. } else {
  50. showErrorPopup('图片上传成功,但未获取到Markdown链接');
  51. }
  52. },
  53. onerror: function(response) {
  54. showErrorPopup('图片上传遇到错误,请检查网络或稍后重试。');
  55. }
  56. });
  57. }
  58.  
  59. function insertToEditor(markdownLink) {
  60. var codeMirrorElement = document.querySelector('.CodeMirror');
  61. if (codeMirrorElement) {
  62. var codeMirrorInstance = codeMirrorElement.CodeMirror;
  63. if (codeMirrorInstance) {
  64. var cursor = codeMirrorInstance.getCursor();
  65. codeMirrorInstance.replaceRange(markdownLink + '\n', cursor);
  66. }
  67. }
  68. }
  69.  
  70. function showErrorPopup(errorMessage) {
  71. var popup = document.createElement('div');
  72. popup.style.position = 'fixed';
  73. popup.style.right = '20px';
  74. popup.style.bottom = '20px';
  75. popup.style.backgroundColor = 'red';
  76. popup.style.color = 'white';
  77. popup.style.padding = '10px';
  78. popup.style.borderRadius = '5px';
  79. popup.style.zIndex = '10000';
  80. popup.textContent = errorMessage;
  81.  
  82. var closeButton = document.createElement('button');
  83. closeButton.textContent = 'X';
  84. closeButton.style.marginLeft = '10px';
  85. closeButton.style.color = 'white';
  86. closeButton.style.backgroundColor = 'transparent';
  87. closeButton.style.border = 'none';
  88. closeButton.onclick = function() {
  89. popup.remove();
  90. };
  91.  
  92. popup.appendChild(closeButton);
  93. document.body.appendChild(popup);
  94. setTimeout(function() {
  95. if (popup) {
  96. popup.remove();
  97. }
  98. }, 5000);
  99. }
  100. })();

QingJ © 2025

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