getzhidaofile

获取百度知道附件下载地址

  1. // ==UserScript==
  2. // @name getzhidaofile
  3. // @namespace http://userscripts.org/scripts/show/176807
  4. // @description 获取百度知道附件下载地址
  5. // @author 酷企鹅Link
  6. // @version 1.0.20.11
  7. // @include http://zhidao.baidu.com/question/*
  8. // @include http://zhidao.baidu.com/link?url=*
  9. // @grant none
  10. // @run-at document-end
  11. // ==/UserScript==
  12. //方法一
  13. try {
  14. [
  15. ].forEach.call(document.getElementsByTagName('file'), function (e) {
  16. if (e.getAttribute('wealth') - 0) e.setAttribute('wealth', 0)
  17. })
  18. } catch (e) {
  19. //方法二
  20. var gd,
  21. gd0,
  22. gd1,
  23. gd2,
  24. i,
  25. j,
  26. tmp;
  27. gd0 = document.getElementsByTagName('div');
  28. gd = new Array();
  29. for (i = 0; i < gd0.length; i++) {
  30. if (gd0[i].id && (gd0[i].id.substring(0, 15) == 'answer-content-' || gd0[i].id.substring(0, 18) == 'recommend-content-' || gd0[i].id.substring(0, 13) == 'best-content-')) gd.push(gd0[i]);
  31. }
  32. gd2 = new Array();
  33. gd0 = '[';
  34. for (i = 0; i < gd.length; i++) {
  35. gd1 = gd[i].getElementsByTagName('file');
  36. for (j = 0; j < gd.length; j++) {
  37. gd0 += '{\'' + gd1[j].getAttribute('name') + '\':\'' + gd1[j].getAttribute('link') + '\'}';
  38. }
  39. }
  40. gd0 += ']';
  41. if (gd0.length > 9) {
  42. gd2 = eval(gd0);
  43. waitload();
  44. }
  45. function waitload() {
  46. if (document.readyState != 'complete') return setTimeout(waitload, 1000);
  47. var gda,
  48. a,
  49. tmp1,
  50. tmp2,
  51. tmp3;
  52. for (var i = 0; i < gd.length; i++) {
  53. gda = gd[i].querySelector('.file-inner');
  54. for (a in gd2[i]) {
  55. try {
  56. tmp2 = gda.querySelector('.i-file-down').parentNode;
  57. tmp2.outerHTML = '<div id="gd_btn' + i + '" class="' + tmp2.getAttribute('class') + '">' + tmp2.innerHTML + '</div>';
  58. tmp2 = document.getElementById('gd_btn' + i);
  59. tmp2.onclick = function (m) {
  60. return function () {
  61. window.open(m);
  62. }
  63. }('http://pan.baidu.com' + gd2[i][a]);
  64. tmp3 = tmp2.parentNode.firstElementChild;
  65. tmp3.outerHTML = '<div id="gd_ico' + i + '" style="cursor:pointer" class="' + tmp3.getAttribute('class') + '">' + tmp3.innerHTML + '</div>';
  66. tmp3 = document.getElementById('gd_ico' + i);
  67. tmp3.onclick = tmp2.onclick;
  68. tmp1 = tmp2.parentNode.querySelector('.info.grid').firstElementChild.firstElementChild;
  69. tmp1.outerHTML = '<div id="gd_a' + i + '" style="display:inline;cursor:pointer" class="' + tmp1.getAttribute('class') + '" title="' + tmp1.getAttribute('title') + '">' + tmp1.innerHTML + '</div>';
  70. tmp1 = document.getElementById('gd_a' + i);
  71. tmp1.onmouseover = function () {
  72. this.style['text-decoration'] = 'underline';
  73. }
  74. tmp1.onmouseout = function () {
  75. this.style['text-decoration'] = 'none';
  76. }
  77. tmp1.onclick = tmp2.onclick;
  78. }
  79. catch (e) {
  80. console.log(e);
  81. }
  82. }
  83. }
  84. }
  85. }