出于某种原因,我的 ISP 阻止了以下 URL:
http://assets.tumblr.com/javascript/prototype_and_effects.js
Chrome 控制台状态:
Failed to load resource: the server responded with a status of 403 (URLBlocked)
结果是我无法正确使用 Tumblr,因为很多功能都依赖于这个脚本。我已经联系了我的 ISP 并要求他们停止阻止此 URL,但同时我想对此采取一些措施。
如何从外部加载此资源?它可以是小书签解决方案、用户脚本/Greasemonkey 或您能想到的任何其他东西。
最佳答案
A 403 status意味着服务器 (assets.tumblr.com) 阻止了请求,而不是您的 ISP。服务器这样做的最常见原因是 (a) 因为您没有以足够的访问权限登录,和/或 (b) 服务器没有收到它想要的引荐来源 header 和/或 cookie,和/或 (c ) 请求来自服务器已列入黑名单的 IP 地址。使用代理服务器可以触发某些网站的任何或所有这些。
这意味着如果您或您的代理服务器被阻止访问该文件,那么用户脚本将使用的注入(inject)远程 javascript 的标准方法也将被阻止。
为了解决这个问题,Greasemonkey 可以从本地副本回填 javascript 文件。为此:
- 创建文件,
Insure Tumbler has prototype.user.js
,如下所示。将它放在计算机上的temp
文件夹以外的目录中。 - 下载the
prototype_and_effects.js
file您引用并将其放在同一文件夹中。您可能必须使用不同的(或没有代理),或不同的浏览器配置文件,或其他。 (对我来说,只需右键单击前面的链接即可下载。) - 使用 Greasemonkey 安装脚本。 (Firefox:文件 -> 打开(CtrlO)会起作用。)
- 脚本测试
Prototype
和Effect
库,如果缺少一个,就在本地加载它们。 可能需要更多才能让 Tumblr 再次工作,但如果是这样,那超出了这个问题的范围。 - 适用于 Firefox+Greasemonkey。应在 Chrome+Tampermonkey 中工作(未测试),不在不支持
@resource
的地方工作,例如直接 Chrome。
// ==UserScript==
// @name _Backfill Prototype and Effect libraries on Tumblr pages
// @match http://tumblr.com/*
// @match http://www.tumblr.com/*
// @match https://tumblr.com/*
// @match https://www.tumblr.com/*
// @resource PandE_src prototype_and_effects.js
// @grant GM_getResourceText
// ==/UserScript==
//-- Does this page load prototype_and_effects.js?
var protoScriptNode = document.querySelector ("script[src*='prototype_and_effects']");
if (protoScriptNode) {
//console.log ("Page uses prototype_and_effects.js.");
//-- Are Prototype and Effects loaded?
var P = unsafeWindow.Prototype;
var E = unsafeWindow.Effect;
if (P && P.Version && E && E.BlindDown) {
//console.log ("Everything's loaded, no action needed.");
}
else {
//console.log ("Loading prototype_and_effects.js");
var PandE_src = GM_getResourceText ("PandE_src");
var scriptNode = document.createElement ('script');
scriptNode.type = "text/javascript";
scriptNode.textContent = PandE_src;
var targ = document.getElementsByTagName ('head')[0];
targ.appendChild (scriptNode);
}
}
else {
//-- No action needed
//console.log ("Page doesn't use prototype_and_effects.js.");
}
关于javascript - 当它被 403 状态阻止时,从外部源加载 javascript 资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14338731/