Skip to content

Commit

Permalink
Update Load pictures on ODSW.user.js
Browse files Browse the repository at this point in the history
  • Loading branch information
owendswang authored Mar 5, 2024
1 parent c2704ac commit df4541f
Showing 1 changed file with 42 additions and 8 deletions.
50 changes: 42 additions & 8 deletions Load pictures on ODSW.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,41 @@
// @name Load pictures on ODSW
// @name:zh-CN 加载ODSW网站上的图片
// @namespace https://www.owendswang.com/
// @version 0.3.2
// @version 0.4.0
// @description Load pictures from weibo.com without limitation on 'owendswang.com'.
// @description:zh-CN 跳过微博图床外链限制,加载“owendswang.com”网站上的微博外链图片。
// @icon https://avatars.githubusercontent.com/u/9076865?s=40&v=4
// @author OWENDSWANG
// @license MIT
// @homepage https://greasyfork.org/scripts/455376
// @supportURL https://github.com/owendswang/Load-pictures-on-ODSW
// @match https://www.owendswang.com/
// @match https://www.owendswang.com/?*
// @match https://www.owendswang.com/weibo/*
// @match https://www.owendswang.com/weixin/*
// @run-at document-end
// @grant GM_xmlhttpRequest
// @grant GM_notification
// @connect sinaimg.cn
// @connect owendswang.com
// @connect weibocdn.com
// ==/UserScript==

(function() {
'use strict';

/*
function saveAs(blob, name) {
const link = document.createElement("a");
link.style.display = "none";
link.href = URL.createObjectURL(blob);
link.download = name;
link.target = '_blank';
document.body.appendChild(link);
link.click();
const timeout = setTimeout(() => {
URL.revokeObjectURL(link.href);
link.parentNode.removeChild(link);
}, 1000);
}
*/
const getImage = (el) => {
const url = el.getAttribute('data-src');
if(url.startsWith('http')) {
Expand All @@ -36,16 +50,36 @@
'Origin': 'https://weibo.com/'
},
onload: function ({ status, response }) {
let blobUrl = URL.createObjectURL(response);
if(status === 200) {
if(el.tagName === "IMG") {
el.src = URL.createObjectURL(response);
el.src = blobUrl;
} else if (el.tagName === "DIV") {
el.style.backgroundImage = 'url(\'' + URL.createObjectURL(response) + '\')';
el.style.backgroundImage = 'url(\'' + blobUrl + '\')';
} else if (el.tagName === "VIDEO") {
el.setAttribute('poster', URL.createObjectURL(response))
el.setAttribute('poster', blobUrl)
} else if (el.tagName === "SOURCE" && el.parentElement.tagName === "VIDEO") {
el.src = blobUrl;
el.parentElement.load();
}
}
}
/*let decodedSrc = decodeURIComponent(url);
let fileName;
if (decodedSrc.endsWith('.mov')) {
fileName = decodedSrc.split('/')[decodedSrc.split('/').length - 1];
fileName = fileName.split('?')[0];
} else {
fileName = decodedSrc.split('?')[0];
fileName = fileName.split('/')[fileName.split('/').length - 1];
}
saveAs(response, fileName);*/
},
onabort: function() { console.log('aborted'); },
onerror: function() { console.log('error'); },
onloadstart: function() { console.log('load started'); },
onprogress: function() { /*console.log('progressing');*/ },
onreadystatechange: function() { console.log('ready state changed'); },
ontimeout: function() { console.log('timeout'); },
})
}
}
Expand Down

0 comments on commit df4541f

Please sign in to comment.