🏠 Home 

Greasy Fork is available in English.

(New Format)BaiduNetDisk Fake Quick Save (新型格式)百度网盘秒传(偽)链接提取 转存

BaiduPan for generating links and saving files. 百度網盤轉存(偽)


安装此脚本?
  1. // ==UserScript==
  2. // @name (New Format)BaiduNetDisk Fake Quick Save (新型格式)百度网盘秒传(偽)链接提取 转存
  3. // @name BaiduPan for generating links and saving files. 百度网盘转存(偽)
  4. // @name:zh BaiduPan for generating links and saving files. 百度网盘转存(偽)
  5. // @name:zh-TW BaiduPan for generating links and saving files. 百度網盤轉存(偽)
  6. // @name:en BaiduNetDisk for generating links and saving files.
  7. // @namespace http://tampermonkey.net/
  8. // @version 0.1
  9. // @description BaiduPan for generating links and saving files. 百度網盤轉存(偽)
  10. // @description:zh-tw 百度網盤轉存(偽)
  11. // @description:en BaiduPan for generating links and saving files.
  12. // @author kamisato
  13. // @match *://pan.baidu.com/*
  14. // @grant GM_xmlhttpRequest
  15. // @noframes
  16. // @license MIT
  17. // ==/UserScript==
  18. (function() {
  19. 'use strict';
  20. var uk;
  21. window.addEventListener('load', function() {
  22. function extractUk() {
  23. const scripts = document.getElementsByTagName('script');
  24. const ukRegex = /"uk":"(\d+)"/;
  25. for (let script of scripts) {
  26. if (script.textContent.includes('window.locals')) {
  27. const matches = ukRegex.exec(script.textContent);
  28. if (matches && matches.length > 1) {
  29. return matches[1];
  30. }
  31. }
  32. }
  33. return null;
  34. }
  35. uk = extractUk();
  36. if (uk) {
  37. console.log('Extracted UK:', uk);
  38. } else {
  39. console.log('UK not found');
  40. }
  41. const toolbar = document.querySelector('.wp-s-agile-tool-bar__header');
  42. if (toolbar) {
  43. const generateLinkButton = createButton('Generate Link', 'generate-link');
  44. generateLinkButton.addEventListener('click', generateLink);
  45. const saveButton = createButton('Save By Link', 'save');
  46. saveButton.addEventListener('click', showSaveDialog);
  47. toolbar.appendChild(generateLinkButton);
  48. toolbar.appendChild(saveButton);
  49. }
  50. });
  51. function createButton(text, className) {
  52. const button = document.createElement('button');
  53. button.textContent = text;
  54. button.className = `btn ${className}`;
  55. return button;
  56. }
  57. function generateLink() {
  58. const links = [];
  59. let fidLists = [];
  60. let fidListAdded = false;
  61. fidLists = getSelectedFidList();
  62. if (fidLists.length === 0) {
  63. return;
  64. }
  65. showLoadingDialog();
  66. function makeRequest(index) {
  67. if (index >= 3) {
  68. const jsonStr = JSON.stringify({ links, fidLists });
  69. const jsonStr1 = JSON.stringify({ links, fidLists: fidLists });
  70. const base64Encoded = btoa(jsonStr1);
  71. updateDialogWithResponse(base64Encoded);
  72. return;
  73. }
  74. const pwd = generateRandomPassword();
  75. fidLists = getSelectedFidList();
  76. const data = `period=0&pwd=${pwd}&eflag_disable=true&channel_list=[]&schannel=4&fid_list=[${fidLists}]`;
  77. GM_xmlhttpRequest({
  78. method: "POST",
  79. url: `https://pan.baidu.com/share/set?channel=chunlei&clienttype=0&app_id=250528&web=1`,
  80. headers: { "Content-Type": "application/x-www-form-urlencoded" },
  81. data: data,
  82. onload: function(response) {
  83. const respJson = JSON.parse(response.responseText);
  84. const surl = extractSurl(respJson.link);
  85. const link = `${surl}&pwd=${pwd}&shareid=${respJson.shareid}&realNameVerify=${uk}`;
  86. links.push(link);
  87. //fidLists.push(fidList.join(','));
  88. makeRequest(index + 1);
  89. },
  90. onerror: function(error) {
  91. console.error('Request failed', error);
  92. makeRequest(index + 1);
  93. }
  94. });
  95. }
  96. makeRequest(0);
  97. }
  98. function extractSurl(fullLink) {
  99. const parts = fullLink.split('/');
  100. const lastPart = parts[parts.length - 1];
  101. return lastPart.substring(1);
  102. }
  103. function generateRandomPassword() {
  104. const characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
  105. let r###lt = '';
  106. for (let i = 0; i < 4; i++) {
  107. r###lt += characters.charAt(Math.floor(Math.random() * characters.length));
  108. }
  109. return r###lt;
  110. }
  111. function getSelectedFidList() {
  112. const selectedRows = document.querySelectorAll('.wp-s-table-skin-hoc__tr.wp-s-pan-table__body-row.mouse-choose-item.selected');
  113. return Array.from(selectedRows, row => row.getAttribute('data-id'));
  114. }
  115. function showLoadingDialog() {
  116. const modal = document.createElement('div');
  117. modal.className = 'modal loading-modal';
  118. modal.innerHTML = `
  119. <div class="modal-dialog loading-dialog">
  120. <div class="modal-content">
  121. <div class="modal-body" style="text-align: center;">
  122. <p style="font-size: 20px;">Generating...</p>
  123. </div>
  124. </div>
  125. </div>
  126. `;
  127. document.body.appendChild(modal);
  128. }
  129. function updateDialogWithResponse(responseText) {
  130. const modalBody = document.querySelector('.modal .modal-body');
  131. if (modalBody) {
  132. modalBody.innerHTML = `
  133. <textarea id="generatedResponse" class="form-control response-textarea" readonly>${responseText}</textarea>
  134. <div class="modal-footer">
  135. <button class="btn btn-success" id="copyButton">Copy</button>
  136. <button class="btn btn-secondary" onclick="this.closest('.modal').remove()">Close</button>
  137. </div>
  138. `;
  139. document.getElementById('copyButton').addEventListener('click', copyToClipboard);
  140. } else {
  141. console.error('Modal body not found');
  142. }
  143. }
  144. function copyToClipboard() {
  145. const responseField = document.getElementById('generatedResponse');
  146. if (navigator.clipboard && window.isSecureContext) {
  147. navigator.clipboard.writeText(responseField.value)
  148. .then(() => {
  149. document.getElementById('copyButton').textContent = 'Copied';
  150. })
  151. .catch(err => {
  152. console.error('error: ', err);
  153. });
  154. } else {
  155. responseField.select();
  156. document.execCommand('copy');
  157. document.getElementById('copyButton').textContent = 'Copied';
  158. }
  159. }
  160. function updateDialogWithLink(link) {
  161. const modalBody = document.querySelector('.modal .modal-body');
  162. modalBody.innerHTML = `
  163. <div class="link-display">
  164. <label for="generatedLink">Generated Link:</label>
  165. <input type="text" id="generatedLink" value="${link}" class="form-control" readonly>
  166. </div>
  167. <div class="modal-footer">
  168. <button class="btn btn-success" onclick="navigator.clipboard.writeText('${link}')">Copy</button>
  169. <button class="btn btn-secondary" onclick="this.closest('.modal').remove()">Close</button>
  170. </div>
  171. `;
  172. }
  173. function tryTransfer(links, fidList, pathInput, attempt, triedIndices = []) {
  174. if (attempt === 0) showTransferringDialog();
  175. if (attempt >= links.length) {
  176. console.error('Failed...');
  177. document.querySelector('.transferring-modal').remove();
  178. showTransferR###ltDialog(false);
  179. return;
  180. }
  181. let remainingIndices = links.map((_, index) => index).filter(index => !triedIndices.includes(index));
  182. let randomIndex = remainingIndices[Math.floor(Math.random() * remainingIndices.length)];
  183. triedIndices.push(randomIndex);
  184. const randomLink = links[randomIndex];
  185. const { surl, pwd, shareid, realNameVerify } = parseLink(randomLink);
  186. const verifyUrl = `https://pan.baidu.com/share/verify?surl=${surl}&channel=chunlei&web=1&app_id=250528`;
  187. const verifyOptions = {
  188. method: 'POST',
  189. headers: {
  190. 'Content-Type': 'application/x-www-form-urlencoded',
  191. 'Referer': 'https://pan.baidu.com'
  192. },
  193. body: `pwd=${pwd}`
  194. };
  195. fetch(verifyUrl, verifyOptions)
  196. .then(response => response.json())
  197. .then(data => {
  198. if (data && data.randsk) {
  199. transferFile(shareid, data.randsk, realNameVerify, fidList, pathInput, () => {
  200. tryTransfer(links, fidList, pathInput, attempt + 1, triedIndices);
  201. });
  202. } else {
  203. tryTransfer(links, fidList, pathInput, attempt + 1, triedIndices);
  204. }
  205. })
  206. .catch(error => {
  207. tryTransfer(links, fidList, pathInput, attempt + 1, triedIndices);
  208. });
  209. }
  210. function showTransferringDialog() {
  211. const modal = document.createElement('div');
  212. modal.className = 'modal transferring-modal';
  213. modal.innerHTML = `
  214. <div class="modal-dialog">
  215. <div class="modal-content">
  216. <div class="modal-body" style="text-align: center;">
  217. <p style="font-size: 20px;">Saving...</p>
  218. </div>
  219. </div>
  220. </div>
  221. `;
  222. document.body.appendChild(modal);
  223. }
  224. function showTransferR###ltDialog(success) {
  225. const message = success ? "Success" : "Fail";
  226. const modal = document.createElement('div');
  227. modal.className = 'modal transfer-r###lt-modal';
  228. modal.innerHTML = `
  229. <div class="modal-dialog">
  230. <div class="modal-content">
  231. <div class="modal-body" style="text-align: center;">
  232. <p style="font-size: 20px;">${message}</p>
  233. </div>
  234. <div class="modal-footer">
  235. <button class="btn btn-secondary" onclick="this.closest('.modal').remove()">Close</button>
  236. </div>
  237. </div>
  238. </div>
  239. `;
  240. document.body.appendChild(modal);
  241. }
  242. function transferFile(shareid, sekey, realNameVerify, fidList, path, errorCallback) {
  243. const transferUrl = `https://pan.baidu.com/share/transfer?shareid=${shareid}&from=${realNameVerify}&sekey=${sekey}&ondup=newcopy&async=1&channel=chunlei&web=1&app_id=250528`;
  244. const transferOptions = {
  245. method: 'POST',
  246. headers: {
  247. 'Content-Type': 'application/x-www-form-urlencoded',
  248. 'Referer': 'https://pan.baidu.com'
  249. },
  250. body: `fsidlist=[${fidList}]&path=${path}`
  251. };
  252. console.log(transferUrl);
  253. fetch(transferUrl, transferOptions)
  254. .then(response => response.json())
  255. .then(respJson => {
  256. if (respJson.errno === 0) {
  257. document.querySelector('.transferring-modal').remove();
  258. showTransferR###ltDialog(true);
  259. } else {
  260. errorCallback();
  261. }
  262. })
  263. .catch(error => {
  264. errorCallback();
  265. });
  266. }
  267. function showSaveDialog() {
  268. const modal = document.createElement('div');
  269. modal.className = 'modal';
  270. modal.innerHTML = `
  271. <div class="modal-dialog">
  272. <div class="modal-content">
  273. <div class="modal-body">
  274. <input type="text" id="linkInput" class="form-control" placeholder="link">
  275. <input type="text" id="pathInput" class="form-control" placeholder="/???,default root path.">
  276. </div>
  277. <div class="modal-footer">
  278. <button class="btn btn-primary" id="saveButton">Save it!</button>
  279. <button class="btn btn-secondary" onclick="this.closest('.modal').remove()">Close</button>
  280. </div>
  281. </div>
  282. </div>
  283. `;
  284. document.body.appendChild(modal);
  285. document.getElementById('saveButton').addEventListener('click', function() {
  286. const linkInput = document.getElementById('linkInput').value;
  287. const pathInput = document.getElementById('pathInput').value;
  288. let encodedPath = encodeURIComponent(pathInput);
  289. if (encodedPath === '') {
  290. encodedPath = '%2f';
  291. }
  292. try {
  293. const linksArray = atob(linkInput);
  294. const parsedData = JSON.parse(linksArray);
  295. const links = parsedData.links;
  296. const fidList = parsedData.fidLists;
  297. tryTransfer(links, fidList, encodedPath, 0);
  298. } catch (error) {
  299. console.error(error);
  300. }
  301. });
  302. }
  303. function parseLink(link) {
  304. const [surl, pwdPart, shareidPart, realNamePart] = link.split('&');
  305. const pwd = pwdPart.split('=')[1];
  306. const shareid = shareidPart.split('=')[1];
  307. const realNameVerify = realNamePart.split('=')[1];
  308. return { surl, pwd, shareid, realNameVerify };
  309. }
  310. const style = document.createElement('style');
  311. style.textContent = `
  312. .btn {
  313. background-color: #06a7ff;
  314. color: white;
  315. font-weight: 700;
  316. padding: 8px 24px;
  317. height: 32px;
  318. font-size: 14px;
  319. border-radius: 16px;
  320. border: none;
  321. margin-left: 10px;
  322. cursor: pointer;
  323. }
  324. .modal {
  325. position: fixed;
  326. top: 50%;
  327. left: 50%;
  328. transform: translate(-50%, -50%);
  329. background-color: white;
  330. padding: 20px;
  331. border-radius: 10px;
  332. box-shadow: 0px 0px 10px rgba(0,0,0,0.5);
  333. z-index: 1000;
  334. }
  335. .modal-dialog {
  336. width: auto;
  337. }
  338. .modal-content {
  339. padding: 15px;
  340. }
  341. .modal-body {
  342. padding: 10px 0;
  343. }
  344. .modal-footer {
  345. text-align: center;
  346. padding: 10px 0;
  347. }
  348. .link-display {
  349. margin-bottom: 15px;
  350. }
  351. .link-display input {
  352. width: 100%;
  353. padding: 6px 12px;
  354. margin-top: 5px;
  355. font-size: 14px;
  356. line-height: 1.42857143;
  357. color: #555;
  358. background-color: #fff;
  359. border: 1px solid #ccc;
  360. border-radius: 4px;
  361. box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
  362. }
  363. .link-display label {
  364. font-weight: 700;
  365. }
  366. .form-control {
  367. width: 100%;
  368. padding: 6px 12px;
  369. font-size: 14px;
  370. line-height: 1.42857143;
  371. color: #555;
  372. background-color: #fff;
  373. border: 1px solid #ccc;
  374. border-radius: 4px;
  375. box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
  376. }
  377. .modal {
  378. position: fixed;
  379. top: 50%;
  380. left: 50%;
  381. transform: translate(-50%, -50%);
  382. width: 30vw;
  383. background-color: white;
  384. padding: 20px;
  385. border-radius: 10px;
  386. box-shadow: 0px 0px 10px rgba(0,0,0,0.5);
  387. z-index: 1000;
  388. overflow: auto;
  389. }
  390. .loading-dialog {
  391. width: 30%;
  392. }
  393. .response-textarea {
  394. height: 200px;
  395. }
  396. .modal-dialog {
  397. width: 100%;
  398. }
  399. .modal-content {
  400. width: 100%;
  401. }
  402. .modal-body {
  403. padding: 10px 0;
  404. }
  405. .modal-footer {
  406. text-align: center;
  407. padding: 10px 0;
  408. }
  409. .link-display {
  410. margin-bottom: 15px;
  411. }
  412. .link-display input, .form-control {
  413. width: 100%;
  414. }
  415. text-area {
  416. min-height: 400px;
  417. }
  418. `;
  419. document.head.appendChild(style);
  420. })();