Greasy Fork 还支持 简体中文。

steamdb.info - download depot sha1 file

5/30/2023, 5:53:13 PM

  1. // ==UserScript==
  2. // @name steamdb.info - download depot sha1 file
  3. // @namespace Violentmonkey Scripts
  4. // @match https://steamdb.info/depot/*
  5. // @grant none
  6. // @version 1.3
  7. // @author klaufir
  8. // @license MIT
  9. // @description 5/30/2023, 5:53:13 PM
  10. // ==/UserScript==
  11.  
  12. // Function to download data to a file
  13. // https://stackoverflow.com/a/30832210
  14. function download(data, filename, type) {
  15. var file = new Blob([data], {type: type});
  16. if (window.navigator.msSaveOrOpenBlob) // IE10+
  17. window.navigator.msSaveOrOpenBlob(file, filename);
  18. else { // Others
  19. var a = document.createElement("a"),
  20. url = URL.createObjectURL(file);
  21. a.href = url;
  22. a.download = filename;
  23. document.body.appendChild(a);
  24. a.click();
  25. setTimeout(function() {
  26. document.body.removeChild(a);
  27. window.URL.revokeObjectURL(url);
  28. }, 0);
  29. }
  30. }
  31.  
  32. function get_metadata() {
  33. var meta_table_trs = document.querySelector('table.table.table-bordered.table-hover.table-responsive-flex')
  34. .querySelectorAll('tr');
  35. var meta_pairs = Array.from(meta_table_trs).map(tr => [tr.querySelector('td:nth-child(1)').innerText, tr.querySelector('td:nth-child(2)').innerText]);
  36. var meta = Object.fromEntries(meta_pairs);
  37. meta['creation_date'] = document.querySelector('time.timeago').getAttribute('datetime').slice(0,10);
  38. return meta;
  39. }
  40.  
  41. function onclick(elem) {
  42. function get_hashes() {
  43. var tr_rows = document.querySelectorAll('#files table tr');
  44. var hashes = Array.from(tr_rows)
  45. .map(e => Array.from(e.querySelectorAll('td')))
  46. .filter(tds => tds.length >= 5 && tds[1].innerText != 'NULL')
  47. .map(tds => ({filename: tds[0].innerText, hash: tds[1].innerText}));
  48. //var hashes = Array.from($('.file-tree').DataTable().rows().data()).map(row => ({filename: row[0], hash: row[1]})).filter(row => row.hash != 'NULL');
  49. return hashes.map(e => `${e.hash} *${e.filename}\r\n`).join('');
  50. }
  51.  
  52. var meta = get_metadata();
  53. var filename = `depot-${meta['Depot ID']}-build-${meta['Build ID']}-manifest-${meta['Manifest ID']}-${meta['creation_date']}.sha1`;
  54. download(get_hashes(), filename, 'text/plain');
  55. }
  56.  
  57. function main() {
  58. var files_h2 = document.querySelector('div#files h2');
  59. var br = document.createElement('br');
  60. var btn = document.createElement('button');
  61. btn.innerText = 'download sha1 file'
  62. files_h2.appendChild(br);
  63. files_h2.appendChild(btn);
  64. btn.onclick = onclick;
  65.  
  66.  
  67. var select = document.querySelector('select');
  68. select.selectedIndex = 5
  69. select.dispatchEvent(new Event('change'))
  70. }
  71.  
  72.  
  73. if (document.querySelector('a[href$="?show_hashes"]') === null
  74. && document.querySelector('div[style="margin-left:auto;align-self:center"] a[href^="/login/?page=depot"]') === null ) {
  75.  
  76. main();
  77. }