我有一个脚本,我希望在导航到任何网站时运行,但它只在某些网站上运行。如何让它始终在没有推荐人的情况下运行,并保留cookie?
function getCookie(c_name) {
var i, x, y, ARRcookies = document.cookie.split(";");
for (i = 0; i < ARRcookies.length; i += 1) {
x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
x = x.replace(/^\s+|\s+$/g, "");
if (x === c_name) {
return (unescape(y))
}
}
}
// <![CDATA[
jQuery(function() {
var sel = 'iframe';
var x = document.referrer;
var y = x.search("facebook");
var z = x.search("//t.co");
var w = x.search("twitter");
if (((y > 0) || (z > 0) || (w > 0)) && (getCookie('clickedad'))) {
$(sel).hide();
}
$(sel).iframeTracker({
blurCallback: function() {
var now = new Date();
var time = now.getTime();
time += 12*60*60*1000;
now.setTime(time);
document.cookie =
'clickedad=1' +
'; expires=' + now.toUTCString() +
'; path=/';
$(sel).fadeOut();
$('#escuro').hide();
$('#tela').hide();
}
});
});
// ]]>
$(function() {
var x = document.referrer;
var y = x.search("facebook");
var z = x.search("//t.co");
var w = x.search("twitter");
if (((y > 0) || (z > 0) || (w > 0)) && (!getCookie('clickedad'))) {
var xbanner = 1 + Math.floor(Math.random() * 100);
var ybanner = 1 + Math.floor(Math.random() * 100);
$('body').prepend('<div id="escuro" style="width:100%; height:100%; z-index:999999; background:#000; opacity:0.8; -moz-opacity:0.7; filter:alpha(opacity=70); position:fixed;"></div><div id="tela" style="width:970px; height:400px; top:370px; left:50%; margin-top:' + (-ybanner) + 'px; margin-left:' + (-525 - xbanner) + 'px; position:absolute; z-index:9999999;"><a href="http://goo.gl/7GGRwe" target="_blank"><img src="http://i.imgur.com/cP5movw.png" border="0" width="970" height="400" /></a></div>');
$('#anuncioad').css({
"position": "relative",
"z-index": "99999999",
"opacity": "0",
"-moz-opacity": "0",
"filter": "alpha(opacity=0)"
});
setTimeout(function() {
$('#escuro').hide();
$('#tela').hide();
}, 120000);
}
});
答案 0 :(得分:0)
我创建了一个 Chrome扩展程序来运行一些自定义代码,以便在删除后恢复我的Twitter背景。基本上它会检查浏览到的每个页面的URL,如果它匹配,则在该站点上运行。
注意:这仅适用于Chrome,但可以针对浏览的每个页面运行。
清单文件低于......
{
"manifest_version": 2,
"name": "Restore Twitter Background",
"description": "Allow user to add back their twitter background.",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"content_scripts":[{
"matches": ["https://twitter.com/*"],
"css": ["css.css"]
}]
}
注意content_scripts和匹配,以便它只针对Twitter URL运行。我使用CSS来解决我的问题,但你可以在这里包含JS,它应该实现你所追求的目标。