-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathbackground.js
37 lines (34 loc) · 1.01 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function string62to10(number_code) {
number_code = String(number_code);
var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
radix = chars.length,
len = number_code.length,
i = 0,
origin_number = 0;
while (i < len) {
origin_number += Math.pow(radix, i++) * chars.indexOf(number_code.charAt(len - i) || 0);
}
return origin_number;
}
function decode(url) {
var lastIndexOfSlash = url.lastIndexOf('/');
var number = url.substr(lastIndexOfSlash + 1, 8);
if (number.startsWith('00')) {
return string62to10(number);
} else {
return parseInt(number, 16);
}
}
const MENEU_ITEM_ID = 'reverse-weibo-image'
chrome.contextMenus.create({
id: MENEU_ITEM_ID,
title: '查看po主',
contexts: ['image'],
targetUrlPatterns: ["*://*.sinaimg.cn/*"]
});
chrome.contextMenus.onClicked.addListener(function (info) {
if (info.menuItemId == MENEU_ITEM_ID) {
sourceUrl = 'https://weibo.com/u/' + decode(info.srcUrl);
chrome.tabs.create({ url: sourceUrl });
}
})