Random URL redirect from array

前端 未结 8 1217
刺人心
刺人心 2021-01-27 05:37

/** * Political Animals * contentscript.js is loaded on each page(s) listed in manifest.json * This plugin replaces all the images on the website of news sites with pic

8条回答
  •  北恋
    北恋 (楼主)
    2021-01-27 06:12

    Try this solution:

    var size = acceptedWebsites.length;
    
    var x = Math.floor((Math.random()* size)+1); 
    

    Now use loop for value x-1 like

    var location = acceptedWebsites[x-1];
    window.location.href = location;
    

    If we run this in loop ,we will get different value of x every time between 0-size of array and then we can use that random value to randomly redirect.

提交回复
热议问题