Witam,
Napisałem sobie małe rozszerzenie do Chrome, które po upływie danego czasu zasłania zawartość okien białym div'em z polem do podania hasła (to jeszcze kwestia do dopracowania).
Niestety skrypt nie chce współpracować z gmail'em albo ze stronami na których znajdują się mapy od google'a - tzn. w momencie blokowania wyświetla mi się seria błędów (zał.)

a po usunięciu div'a strona gmail'a jest jakby zablokowana i nic nie można kliknąć.
Podrzucam kod, może ktoś coś poradzi.
Manifest.json
{
"manifest_version": 2,
"name": "TabLock",
"description": "TabLock.",
"version": "1.0",
"permissions": [
"tabs", "http://*/", "https://*/"
],
"content_scripts": [
{
"matches": ["<all_urls>"],
"css": ["css/style.css"],
"js": ["js/keyListener.js"]
}
],
"background": {
"persistent": false,
"scripts": ["js/background.js"]
},
"browser_action": {
"default_icon": "images/menu.png",
"default_popup": "menu.html",
"default_title": "Lock tabs"
},
"web_accessible_resources": [
"js/lock.html"
]
}
Background.js
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
if (request.lock == "yes_key"){
chrome.tabs.executeScript({
file: 'js/lock.js'
});
sendResponse({farewell: "Lock JS KEY LISTENER"});
}
if (request.lock == "yes"){
chrome.tabs.query({}, function(tabs){
for (var i = 0; i < tabs.length; i++) {
chrome.tabs.executeScript(tabs[i].id,
{
file: 'js/lock.js'
}, function() {
if (chrome.runtime.lastError) {
console.log(chrome.runtime.lastError.message);
}
});
}
});
sendResponse({farewell: "Lock BY TIMER"});
}
}
);
Panel.js
$(function(){
$('#lock_all').click(function(){
chrome.tabs.query({}, function(tabs){
for (var i = 0; i < tabs.length; i++) {
chrome.tabs.executeScript(tabs[i].id,
{
file: 'js/lock.js'
}, function() {
if (chrome.runtime.lastError) {
console.log(chrome.runtime.lastError.message);
}
});
}
});
});
});
$(function(){
$('#unlock_all').click(function(){
chrome.tabs.query({}, function(tabs){
for (var i = 0; i < tabs.length; i++) {
chrome.tabs.executeScript(tabs[i].id,
{
file: 'js/unlock.js'
}, function() {
if (chrome.runtime.lastError) {
console.log(chrome.runtime.lastError.message);
}
});
}
});
});
});
$(function(){
$('#unlock_this').click(function(){
chrome.tabs.executeScript({
file: 'js/unlock.js'
});
});
});
$(function(){
$('#lock_this').click(function(){
chrome.tabs.executeScript({
file: 'js/lock.js'
});
});
});
keyListener.js
window.onkeydown = function (e) {
e = e || event;
var keyCode = e.keyCode,
letter = (String.fromCharCode(e.keyCode) || '').toLowerCase();
if (e.ctrlKey && 'q' === letter)
{
chrome.runtime.sendMessage({lock: "yes_key"}, function(response) {
console.log(response.farewell);
clearTimeout(t);
});
}
}
var c = 0;
var t;
var czas = 30;
function timer() {
if(c > czas){
clearTimeout(t);
}else{
c = c + 1;
t = setTimeout(window, function(){ timer() }, 1000);
if(c > czas){
chrome.runtime.sendMessage({lock: "yes"}, function(response) {
console.log(response.farewell);
});
}
}
console.log(c);
}
document.addEventListener("mousemove", function(){
c = 0;
});
timer();
lock.js
var pass = chrome.extension.getURL("js/lock.html");
if(document.getElementById("changestateLock") !== null){
document.getElementById("changestateLock").style.display = "inline";
document.body.style.overflow = "hidden";
//console.log("Zablokowano");
}
if(document.getElementById("changestateLock") == null){
document.body.innerHTML += '<div id="changestateLock"><object type="text/html" data=' + pass + '></object></div>';
document.body.style.overflow = "hidden";
//console.log("Zablokowano");
}
unlock.js
if(document.getElementById("changestateLock") !== null){
if(document.getElementById("changestateLock").style.display !== "none"){
document.getElementById("changestateLock").remove();
document.body.style.overflow = "visible";
//window.location.reload();
console.log("Odblokowano");
}
}
Ten post edytował soliniak 30.01.2017, 14:22:02