string = "{'server1':'value','server2':'value'}"
#Now removing { and }
s = string.replace("{" ,"");
finalstring = s.replace("}" , "");
#Splitting the string based on , we get key value pairs
list = finalstring.split(",")
dict ={}
for i in list:
#Get Key Value pairs separately to store in dictionary
keyvalue = i.split(":")
#Replacing the single quotes in the leading.
m= keyvalue[0].strip('\'')
m = m.replace("\"", "")
dict[m] = keyvalue[1].strip('"\'')
print dict
В интерфейсе chrome extension API нет правой панели.
Вы можете сделать это так же, как это делает расширение вашего примера:
background.js
прослушивание сообщений с вкладки background.js
, если вкладка инъецируется (если вам нужно, чтобы ваша работа расширений была правильной на системных страницах) chrome.tabs.executeScript
введите ваше меню div в страницу / приложение для прослушивания, которое откроет ваше меню. background.js
прослушивание значка браузера браузера и сообщите скрипту содержимого о кликах. popup.html
во всплывающем окне по умолчанию. manifest.js
....
"browser_action": {
},
"background": {
"scripts":["background.js"]
},
...
background.js
chrome.browserAction.onClicked.addListener(function(){
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
chrome.tabs.sendMessage(tabs[0].id,"toggle");
})
});
zero width
с стилем display:none;
). Я использую zero width
из-за того, что вам может понадобиться оживить отображение вашего меню с помощью jquery, например, расширение для примера. background.js
. content-script.js
chrome.runtime.onMessage.addListener(function(msg, sender){
if(msg == "toggle"){
toggle();
}
})
var iframe = document.createElement('iframe');
iframe.style.background = "green";
iframe.style.height = "100%";
iframe.style.width = "0px";
iframe.style.position = "fixed";
iframe.style.top = "0px";
iframe.style.right = "0px";
iframe.style.zIndex = "9000000000000000000";
iframe.frameBorder = "none";
iframe.src = chrome.extension.getURL("popup.html")
document.body.appendChild(iframe);
function toggle(){
if(iframe.style.width == "0px"){
iframe.style.width="400px";
}
else{
iframe.style.width="0px";
}
}
manifest.json
"web_accessible_resources": ["popup.html"]