-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
63 lines (58 loc) · 1.97 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
chrome.runtime.onInstalled.addListener(function() {
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
chrome.declarativeContent.onPageChanged.addRules([
{
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { hostContains: '.pinterest'}
})
],
actions: [ new chrome.declarativeContent.ShowPageAction() ]
}
]);
chrome.declarativeContent.onPageChanged.addRules([
{
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { hostContains: '.pinterdev'}
})
],
actions: [ new chrome.declarativeContent.ShowPageAction() ]
}
]);
});
});
chrome.pageAction.onClicked.addListener(function(tab){
// edit "username" to match your own ldap name!
var username = 'your_username';
var url = tab.url;
var split = tab.url.split(".com/");
var host = split[0];
var params = split.slice(1);
var joined_params = params.join(".com/");
if(host == 'https://api.pinterest'){
chrome.tabs.update(tab.id, {url: "https://api-"+username+".pinterdev.com/" + joined_params});
}
if(host == 'https://api-'+username+'.pinterdev'){
chrome.tabs.update(tab.id, {url: "https://api.pinterest.com/" + joined_params});
}
if(host == 'https://www.pinterest'){
chrome.tabs.update(tab.id, {url: "https://"+username+".pinterdev.com/" + joined_params});
}
if(host == 'https://'+username+'.pinterdev'){
chrome.tabs.update(tab.id, {url: "https://www.pinterest.com/" + joined_params});
}
});
// A generic onclick callback function
function openPinOnClick(info, tab) {
var newURL = "https://www.pinterest.com/pin/"+info.selectionText;
chrome.tabs.create({ url: newURL });
}
// Create one test item for each context type.
var contexts = ["selection"];
for (var i = 0; i < contexts.length; i++) {
var context = contexts[i];
var title = "Open pin from selection";
var id = chrome.contextMenus.create({"title": title, "contexts":[context],
"onclick": openPinOnClick});
}