// ==UserScript== // @name TeraBox DevTools Helper & Direct Download Menu // @version 0.3 // @description Simple script that downlaod terabox file without app // @namespace http://tampermonkey.net/ // @run-at document-start // @grant GM_registerMenuCommand // @grant GM_unregisterMenuCommand // @grant unsafeWindow // @match *://*.1024-terabox.com/* // @match *://*.1024terabox.com/* // @match *://*.1024tera.com/* // @match *://*.bestclouddrive.com/* // @match *://*.dubox.com/* // @match *://*.freeterabox.com/* // @match *://*.gibibox.com/* // @match *://*.mirrobox.com/* // @match *://*.nephobox.com/* // @match *://*.pebibox.com/* // @match *://*.tera1024box.com/* // @match *://*.terabox1024.com/* // @match *://*.terabox.app/* // @match *://*.terabox.com/* // @match *://*.teraboxfree.com/* // @match *://*.terastream.fun/* // @match *://*.terabox.link/* // @match *://*.teraboxlink.com/* // @match *://*.terabox-share.com/* // @match *://*.teraboxshare.com/* // @match *://*.terabox.space/* // @match *://*.teraboxurl.com/* // @match *://*.terabox.zone/* // @match *://*.terafileshare.com/* // @match *://*.teralinkshare.com/* // @match *://*.terareferral.com/* // @match *://*.tera-share.com/* // @match *://*.terasharefile.com/* // @match *://*.terasharelink.com/* // @match *://*.terashareus.com/* // @match *://*.terabox.best/* // @match *://*.teraboxapp.com/* // @license MIT // @downloadURL https://update.greasyfork.icu/scripts/567800/TeraBox%20DevTools%20Helper%20%20Direct%20Download%20Menu.user.js // @updateURL https://update.greasyfork.icu/scripts/567800/TeraBox%20DevTools%20Helper%20%20Direct%20Download%20Menu.meta.js // ==/UserScript== // from: https://global-staticplat.cdn.bcebos.com/general-conf/domain.json (function() { 'use strict'; function download_file(url, filename) { if (!url.length) return const a = document.createElement("a"); a.href = url; a.download = filename; document.body.appendChild(a); a.click(); document.body.removeChild(a); } function update_menu(files) { registeredMenuIds.forEach(id => { GM_unregisterMenuCommand(id); }) registeredMenuIds = [] files.forEach(item => { let menu = GM_registerMenuCommand(item.name, () => { download_file(item.url, item.name); }); registeredMenuIds.push(menu); }); } function response_parse(data) { if (!data) return const files = [] if (data.error_msg && data.error_msg !== "succ") { files.push({ name: "you need to login to download", url: "" }); } else if (data.list) { data.list.forEach(item => { if (item.isdir) { files.push({ name: `${item.server_filename} is dir, open dir to get download link`, url: "" }); } else if (item.dlink) { fileLinkMap[item.server_filename] = item.dlink; files.push({ name: item.server_filename, url: item.dlink }); } }); } update_menu(files); } function intercept_xhr() { function handle_xhr_response(xhr) { const url = xhr._url; if (!url) return; const responseData = JSON.parse(xhr.responseText); if (url.includes("/membership/proxy/user?") || url.includes("/share/list?")) { response_parse(responseData); } } const xhrProto = win.XMLHttpRequest.prototype; const originalOpen = xhrProto.open; const originalSend = xhrProto.send; xhrProto.open = function (method, url) { this._url = url; return originalOpen.apply(this, arguments); }; xhrProto.send = function (body) { this.addEventListener("load", function () { handle_xhr_response(this); }); return originalSend.apply(this, arguments); }; } function disable_debugger_constructor() { const originalConstructor = win.Function.prototype.constructor; win.Function.prototype.constructor = function (str) { if (str && str.includes('debugger')) { return function () {}; } return originalConstructor.apply(this, arguments); }; } function protect_keyboard_shortcut() { win.addEventListener('keydown', function(e) { if (e.keyCode === 123 || (e.ctrlKey && e.shiftKey && e.keyCode === 73)) { e.stopImmediatePropagation(); } }, true); } function protect_right_click() { win.addEventListener('contextmenu', function(e) { e.stopImmediatePropagation(); }, true); } function spoof_window_size() { Object.defineProperty(win, "outerWidth", { get: function () { return win.innerWidth; } }); Object.defineProperty(win, "outerHeight", { get: function () { return win.innerHeight; } }); } function block_anti_debug_intervals() { const originalSetInterval = win.setInterval; win.setInterval = function(fn, delay) { if (typeof fn === 'function') { const fnStr = fn.toString(); if (delay === 2000 && (fnStr.includes('outerWidth') || fnStr.includes('debugger'))) { console.log("[System] Anti-debug loop blocked."); return null; } } return originalSetInterval.apply(this, arguments); }; } function override_default_download() { document.addEventListener('click', async function(e) { const downloadBtn = e.target.closest('.action-bar-download'); if (downloadBtn) { e.preventDefault(); e.stopPropagation(); e.stopImmediatePropagation(); const selectedItems = document.querySelectorAll('.common-file-item.selected'); if (selectedItems.length === 0) { alert('please select file'); return; } let count = 0; for (const item of selectedItems) { const nameEl = item.querySelector('.file-item-name-link'); if (nameEl) { const fileName = nameEl.textContent.trim(); const downloadUrl = fileLinkMap[fileName]; await new Promise(resolve => setTimeout(resolve, count * 3000)); download_file(downloadUrl, fileName); count++; } } } }, true); } let fileLinkMap = {} // you need to use unsafeWindow to unblock debugger detection. const win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window; let registeredMenuIds = [GM_registerMenuCommand( "Initializing...", () => {})] intercept_xhr(); disable_debugger_constructor(); protect_keyboard_shortcut(); protect_right_click(); spoof_window_size(); block_anti_debug_intervals(); override_default_download(); })();