日常の進捗

主に自分のための,行為とその習慣化の記録

Mod: Coding Challenge #82: Image Chrome Extension: The Ex-Kitten-sion!

{
  "manifest_version": 2,
  "name":"Chrome Extension",
  "version": "0.1",
  "web_accessible_resources" : ["images/*.jpg"],
  "content_scripts": [
  {
      "matches" : ["<all_urls>"],
      "js" : ["content.js"]
  }
  ]
}
(function (){

  let files = [
    "nasa-63032.jpg",
    "joel-filipe-191372.jpg",
    "jeremy-thomas-98201.jpg",
    "nasa-53884.jpg",
    "nasa-89125.jpg"
  ];


  let imgs = document.getElementsByTagName('img');
  for(imgElements of imgs){
    let n = Math.floor(Math.random() * files.length);
    let file = 'images/' + files[n];
    console.log(file);
    let url = chrome.extension.getURL(file);
    console.log(url);
    imgElements.src = url;
  }
})();

リファレンス