[英]Bookmarklet/JavaScript to rotate URL
I want to create a Bookmarklet which will load one link out of a list of ten links, order doesn't matter, but weight-age does. 我想创建一个Bookmarklet,它将从十个链接的列表中加载一个链接,顺序无关紧要,但是重量年龄可以。
I tried http://www.htmlbasix.com/textrotator.shtml but it's for rotating a link on a webpage, how to make a Bookmarklet which will open a random URL from the list? 我尝试了http://www.htmlbasix.com/textrotator.shtml,但这是用于旋转网页上的链接的,如何制作一个可以从列表中打开随机URL的书签? Kind of URL rotator script within a bookmark. 书签中的URL旋转脚本类型。
Any efficient way to do that? 有任何有效的方法吗?
Thanks in advance. 提前致谢。
You can't setup bookmarklet to run automatically. 您无法将书签设置为自动运行。 Consider writing browser extension or just use curl
. 考虑编写浏览器扩展或仅使用curl
。
Not automatically. 不是自动的。
Then it varies. 然后就变了。
First, if you're 100% that pages don't redirect you anywhere you can try to use window.location
inside you bookmarklet in next way: 首先,如果您100%认为页面无法将您重定向到任何地方,则可以尝试通过以下方式在小书签中使用window.location
:
var next = urls.indexOf(window.location.href) + 1;
next = next < urls.length ? next : 0;
window.location = urls[next];
If one of pages redirects or messes with url then you can use localStorage
on your own domain and postMessage
to store any data between bookmarklet calls. 如果其中一个页面重定向或弄乱了url,那么您可以在自己的域上使用localStorage
并使用postMessage
在小书签调用之间存储任何数据。
I have found the solution after few tries 经过几次尝试我找到了解决方案
javascript: (function randomlinks() {
var myrandom = Math.round(Math.random() * 9);
var links = new Array();
links[0] = "http://www.javascriptkit.com";
links[1] = "http://www.dynamicdrive.com";
links[2] = "http://www.cssdrive.com";
links[3] = "http://www.codingforums.com";
links[4] = "http://www.news.com";
links[5] = "http://www.gamespot.com";
links[6] = "http://www.msnbc.com";
links[7] = "http://www.cnn.com";
links[8] = "http://news.bbc.co.uk";
links[9] = "http://www.news.com.au";
window.location = links[myrandom];
})()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.