简体   繁体   English

javascript-用于修改URL开头的书签

[英]javascript - Bookmarklet for modifying the start of an URL

My university allows us to access journal articles through the library search engine, which is a hassle to use. 我的大学允许我们通过图书馆搜索引擎来访问期刊文章,这很麻烦。 All it does is modify the URL of a given resource as follows: 它所做的只是修改给定资源的URL,如下所示:

From

https://(www.)database.com/article-link

To

https://0-(www.)database.com.elibrary.qatar-weill.cornell.edu/article-link

Now, I'm looking to make a bookmarklet which prefixes the 0- part to the URL and adds in the .elibrary.qatar-weill.cornell.edu part at the end. 现在,我正在寻找一个书签书签,该书签书签将URL的0-部分作为前缀,并在末尾添加.elibrary.qatar-weill.cornell.edu部分。 As of yet, I've got the second part working by putting the following code into the bookmarklet: 到目前为止,我已经通过将以下代码放入书签来完成第二部分的工作:

javascript:(function(){var l=location;l.href=l.origin+l.href.replace(l.origin,'.elibrary.qatar-weill.cornell.edu');})();

But I can't find a way to add 0- to the start of an URL without everything breaking. 但是我找不到在不破坏所有内容的情况下将0-添加到URL开头的方法。 Any ideas? 有任何想法吗?

How about adding an additional replace method call which affects the l.origin of the URL? 如何添加影响URL的l.origin的其他replace方法调用?

javascript:(function(){var l=location;l.href=l.origin.replace("//", "//0-")+l.href.replace(l.origin,'.elibrary.qatar-weill.cornell.edu');})();

This seeks out // inside the URL's origin (the https://database.com part) and replaces it with //0- . 这会在URL的来源( https://database.com部分)中查找//并将其替换为//0-

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM