Get data url

input resource url and get data url

目前為 2020-06-26 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Get data url
  3. // @namespace https://blog.bgme.me
  4. // @match *://*/*
  5. // @run-at document-idle
  6. // @version 1.0
  7. // @author bgme
  8. // @description input resource url and get data url
  9. // @supportURL https://github.com/yingziwu/Greasemonkey/issues
  10. // @icon -
  11. // @license AGPL-3.0-or-later
  12. // ==/UserScript==
  13.  
  14. 'use strict';
  15.  
  16. unsafeWindow.toDataURL = toDataURL;
  17. unsafeWindow.getDataURL = getDataURL;
  18.  
  19.  
  20. // https://stackoverflow.com/questions/934012/get-image-data-url-in-javascript/42916772#42916772
  21. function toDataURL(url, callback) {
  22. GM.xmlHttpRequest({
  23. method: "GET",
  24. url: url,
  25. responseType: 'blob',
  26. onload(response) {
  27. var fr = new FileReader();
  28.  
  29. fr.onload = function() {
  30. callback(this.result);
  31. }
  32.  
  33. fr.readAsDataURL(response.response);
  34. }
  35. });
  36. }
  37.  
  38. function getDataURL(url) {
  39. toDataURL(url, function(dataurl) {
  40. console.log(dataurl);
  41. });
  42. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址