CRX Downloader

Allows downloading .crx'es from Google's Chrome Web Store

  1. // ==UserScript==
  2. // @name CRX Downloader
  3. // @namespace CRX_Downloader
  4. // @id CRX_Downloader
  5. // @description Allows downloading .crx'es from Google's Chrome Web Store
  6. // @version 0.2
  7. // @grant none
  8. // @author KOLANICH
  9. // @copyright KOLANICH, 2016 (based on http://chrome-extension-downloader.com/how-does-it-work.php and https://github.com/doraemonsk8ers/CRX_Downloader)
  10. // @license Unlicensed
  11. // @homepageURL https://github.com/KOLANICH/CRX_Downloader
  12. // @contributionURL https://github.com/KOLANICH/CRX_Downloader/fork
  13. // @contributionAmount feel free to fork and contribute
  14. // @include https://chrome.google.com/webstore/detail/*/*
  15. // @noframes 1
  16. // @run-at document-idle
  17. // @optimize 1
  18. // ==/UserScript==
  19.  
  20. /*This is free and unencumbered software released into the public domain.
  21.  
  22. Anyone is free to copy, modify, publish, use, compile, sell, or
  23. distribute this software, either in source code form or as a compiled
  24. binary, for any purpose, commercial or non-commercial, and by any
  25. means.
  26.  
  27. In jurisdictions that recognize copyright laws, the author or authors
  28. of this software dedicate any and all copyright interest in the
  29. software to the public domain. We make this dedication for the benefit
  30. of the public at large and to the detriment of our heirs and
  31. successors. We intend this dedication to be an overt act of
  32. relinquishment in perpetuity of all present and future rights to this
  33. software under copyright law.
  34.  
  35. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  36. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  37. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  38. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  39. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  40. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  41. OTHER DEALINGS IN THE SOFTWARE.
  42.  
  43. For more information, please refer to <http://unlicense.org/>*/
  44.  
  45. "use strict";
  46. const chromiumCachedVersion="48.0";
  47. const downloadUriBase="https://clients2.google.com/service/update2/crx";
  48.  
  49. function detectChromium(){
  50. let m=navigator.userAgent.match(/Chrome\/(\d+\.\d+)/);
  51. return {
  52. version:m?m[1]:chromiumCachedVersion,
  53. chromium:!!m
  54. };
  55. }
  56. const chromiumInfo=detectChromium();
  57.  
  58.  
  59. function assembleParams(params){
  60. return Object.keys(params).map(p=>p+(params[p]?"="+encodeURIComponent(params[p]):"")).join("&");
  61. }
  62. function getAddonLink(id){
  63. let a=document.createElement("A");
  64. a.href=downloadUriBase;
  65. a.search=assembleParams({
  66. "response":"redirect",
  67. "prodversion":chromiumInfo.version,
  68. "x":assembleParams({
  69. "id":id,
  70. "installsource":"ondemand",
  71. "uc":null
  72. })
  73. });
  74. return a;
  75. }
  76.  
  77. function parseAddonUri(path){
  78. let a=path.split("/");
  79. return {ID:a[a.length-1],hrID:a[a.length-2]};
  80. }
  81. function getButton(){
  82. return document.body.querySelector("div[role=button]");
  83. }
  84. function getFilename(){
  85. return getAddonName();
  86. }
  87. function getAddonName(){
  88. return document.getElementsByTagName("H1")[0].textContent;
  89. }
  90. function injectDownloadLink(){
  91. let parsed=parseAddonUri(window.location.pathname);
  92. let a=getAddonLink(parsed.ID);
  93. a.download=parsed.hrID+".crx";
  94. a.textContent="Download .CRX";
  95. let btn=getButton();
  96. a.className=btn.className;
  97. if(!chromiumInfo.chromium){
  98. btn.parentNode.replaceChild(a,btn);
  99. }else{
  100. btn.parentNode.insertBefore(a,btn);
  101. btn.style.margin=(btn.nextSibling.getBoundingClientRect().left-btn.getBoundingClientRect().right)+"px";
  102. }
  103. }
  104. setTimeout(injectDownloadLink,3000);