// ==UserScript== // @name Baha imgur upload // @namespace https://blog.maple3142.net/ // @version 0.7.4 // @description add upload to imgur in bahamut // @author maple3142 // @match https://*.gamer.com.tw/* // @match https://blog.maple3142.net/bahamut-imgur-upload.html // @require https://code.jquery.com/jquery-3.2.1.min.js // @grant GM_getValue // @grant GM_setValue // @downloadURL https://update.greasyfork.org/scripts/36735/Baha%20imgur%20upload.user.js // @updateURL https://update.greasyfork.org/scripts/36735/Baha%20imgur%20upload.meta.js // ==/UserScript== ;(function($) { 'use strict' /* * ALBUM_TO_UPLOAD 是你想要上傳的目標相簿 id * 例如相簿 https://imgur.com/a/C8763 的 id 是 C8763 * 請把他貼到 GM_getValue('ALBUM_TO_UPLOAD','') 後面的引號中,變成 GM_getValue('ALBUM_TO_UPLOAD','C8763') * 這樣可以確保 id 不會在腳本更新後被清除,不過如果要修改的需要自己去腳本管理器的儲存空間修改 * Tampermonkey 直接在編輯頁面上面的 Storage 頁面修改就好,其他我就不知道了 */ const ALBUM_TO_UPLOAD = GM_getValue('ALBUM_TO_UPLOAD', '') if (ALBUM_TO_UPLOAD) GM_setValue('ALBUM_TO_UPLOAD', ALBUM_TO_UPLOAD) const debounce = delay => fn => { let de = false return (...args) => { if (de) return de = true fn(...args) setTimeout(() => (de = false), delay) } } const qs = o => Object.keys(o) .map(k => k + '=' + encodeURIComponent(o[k])) .join('&') const insertToRte = c => { // copy from utility_fx.js let a a = bahaRte.win.getSelection() a.getRangeAt && a.rangeCount && ((a = a.getRangeAt(0)), a.deleteContents(), (c = a.createContextualFragment(c)), a.insertNode(c)) } const insertUrlToField = url => { if (unsafeWindow.bahaRte != null) { // full rte editor const ht = $('