Commit 6f30458a by 庄欣

权限判断

parent d089158f
...@@ -4,8 +4,14 @@ ...@@ -4,8 +4,14 @@
"description": "米拍下图工具", "description": "米拍下图工具",
"version": "1.0", "version": "1.0",
"permissions": [ "permissions": [
"tabs" "tabs",
"webRequest",
"cookies",
"*://*.mepai.me/"
], ],
"background": {
"scripts": ["background.js"]
},
"content_scripts": [ "content_scripts": [
{ {
"matches": ["https://www.mepai.me/works/*", "https://www.photosaas.cn/*"], "matches": ["https://www.mepai.me/works/*", "https://www.photosaas.cn/*"],
......
...@@ -9,7 +9,7 @@ setInterval(function () { ...@@ -9,7 +9,7 @@ setInterval(function () {
}, 1000); }, 1000);
var body = $("#__nuxt"); var body = $("#__nuxt");
var accessToken = "";
var img = new Image(); var img = new Image();
var checkedProp = false; var checkedProp = false;
img.src = chrome.extension.getURL("ui.html"); img.src = chrome.extension.getURL("ui.html");
...@@ -138,7 +138,7 @@ function setSelect(dom, all) { ...@@ -138,7 +138,7 @@ function setSelect(dom, all) {
} }
function getImages() { function getImages() {
var worksId; var worksId = getWorksId();
var userNickname; var userNickname;
var userId = ""; var userId = "";
var lists = []; var lists = [];
...@@ -148,18 +148,6 @@ function getImages() { ...@@ -148,18 +148,6 @@ function getImages() {
lists = $(".swiper-wrapper").find("img"); lists = $(".swiper-wrapper").find("img");
var urls = []; var urls = [];
var imgSrc = ""; var imgSrc = "";
var worksString = window.location.href
if (worksString.length > 0 && worksString.indexOf("works") > -1) {
var start = worksString.indexOf("works/") + "works/".length;
var end = worksString.indexOf("?");
if (end <= -1) {
end = worksString.length;
}
var worksId = worksString.substring(start, end)
if (isNaN(worksId)) {
worksId = base64Decode(worksId);
}
}
userNickname = $($(".user-info > span.nickname")[0]).text(); userNickname = $($(".user-info > span.nickname")[0]).text();
$.each(lists, (i,n) => { $.each(lists, (i,n) => {
let fullUrl = n.currentSrc; let fullUrl = n.currentSrc;
...@@ -201,6 +189,22 @@ function getImages() { ...@@ -201,6 +189,22 @@ function getImages() {
return images; return images;
} }
function getWorksId() {
var worksString = window.location.href
if (worksString.length > 0 && worksString.indexOf("works") > -1) {
var start = worksString.indexOf("works/") + "works/".length;
var end = worksString.indexOf("?");
if (end <= -1) {
end = worksString.length;
}
var worksId = worksString.substring(start, end)
if (isNaN(worksId)) {
worksId = base64Decode(worksId);
}
}
return worksId;
}
function base64Decode(input){ function base64Decode(input){
rv = window.atob(input); rv = window.atob(input);
rv = escape(rv); rv = escape(rv);
...@@ -243,35 +247,44 @@ function changeFocus() { ...@@ -243,35 +247,44 @@ function changeFocus() {
function downloadAll() { function downloadAll() {
if (confirm("点击确定开始下载!")) { if (confirm("点击确定开始下载!")) {
var q = $("select[name=quality]").val(); var q = $("select[name=quality]").val();
var uris = [];
$.each($(body).find("input[type='checkbox']:checked"), (i,n) => { $.each($(body).find("input[type='checkbox']:checked"), (i,n) => {
var src = $(n).val(); uris.push($(n).val().replace("https://images.mepai.me", ""));
var isVideo = false; })
if (src.indexOf(".mp4") > -1) { getRawPath(getWorksId(), uris, function(data) {
isVideo = true; var j = 0;
} for (var i in uris) {
var ext = ""; var src = data[uris[i]];
if (q == 720) { var isVideo = false;
if (isVideo) { if (src.indexOf(".mp4") > -1) {
ext = "!HD.mp4"; isVideo = true;
} else {
ext = "!720w.jpg";
} }
} var ext = "";
if (q == 1200) { if (q == 720) {
if (isVideo) {
ext = "!HD.mp4";
} else {
ext = "!720w.jpg";
}
}
if (q == 1200) {
if (isVideo) {
alert("视频下载仅支持720p或者源视频!")
return
}
ext = "!1200w.jpg"
}
var downloadUrl = src + ext;
var n = $(body).find("input[type='checkbox']:checked")[j];
if (isVideo) { if (isVideo) {
alert("视频下载仅支持720p或者源视频!") $.getJSON("https://api.mepai.me/goms/video/sign?path=" + downloadUrl, function(res) {
return downloadResource(res.data, $(n).attr("fileid") + "-" + q, true, $(n));
})
} else {
downloadResource( "https://images.mepai.me" +downloadUrl, $(n).attr("fileid") + "-" + q, false, null);
} }
ext = "!1200w.jpg" j++;
} };
var downloadUrl = $(n).val() + ext;
if (isVideo) {
$.getJSON("https://api.mepai.me/goms/video/sign?path=" + downloadUrl, function(res) {
downloadResource(res.data, $(n).attr("fileid") + "-" + q, true, $(n));
})
} else {
downloadResource(downloadUrl, $(n).attr("fileid") + "-" + q, false, null);
}
}); });
} }
} }
...@@ -337,7 +350,29 @@ function bindChangeWorkEvents() { ...@@ -337,7 +350,29 @@ function bindChangeWorkEvents() {
return false; return false;
} }
function getRawPath(worksId, srcs, callback) {
$.ajax({
type: "post",
url: 'https://api.mepai.me/goms/parse-src',
async: true, // 使用同步方式
data: JSON.stringify( {
'works_id': parseInt(worksId),
'uris': srcs,
}),
headers: {
"accesstoken": accessToken
},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (res) {
if (res.code.toString() != "100001") {
alert("用户未登录,请确认您的权限!");
return ;
}
callback(res.data);
}
});
}
function bindChangeImg() { function bindChangeImg() {
$(".btn-next").click(()=>{ $(".btn-next").click(()=>{
...@@ -346,4 +381,17 @@ function bindChangeImg() { ...@@ -346,4 +381,17 @@ function bindChangeImg() {
$(".btn-prev").click(()=>{ $(".btn-prev").click(()=>{
changeFocus(); changeFocus();
}) })
}
chrome.extension.sendRequest({}, function(response) {
accessToken = response.access_token;
});
function getCookie(key, callback) {
chrome.runtime.sendMessage({
"action": "getCookie",
"key": key,
}, function(response) {
callback(response);
});
} }
\ No newline at end of file
chrome.extension.onRequest.addListener( chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) { function(request, sender, sendResponse) {
chrome.cookies.get({ chrome.cookies.get({
url: "https://www.mepai.me/", url: "https://www.mepai.me/",
name: "auth" name: "auth"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment