无法进行Chrome扩展

时间:2018-08-13 19:07:12

标签: javascript json google-chrome google-chrome-extension

我需要Chrome扩展程序的帮助,我似乎无能为力。我能提供的大部分资源都没有太大帮助。我需要在这里编辑什么?

这是代码: HTML

<!DOCTYPE html>
<html>
<head>
<title>WebApp</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="main.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet'>
</head>
<style>
.loading {
    position: fixed;
    width: 100%;
    height: 100%;
    text-align: center;
    padding-top: 200px;
}
.loading-gif {
    display: block;
    margin: 10px auto;
    height: 50%;
    width: auto;
}
#loading-text {
    font-size: 20px;
    padding: 20px;
}

#myDiv {
  display: none;
}
body {
  margin: 0;
  min-width: 320px;
  max-width: 400px;
  font-family: Roboto, Arial;
  background-color: #fff;
}

/* Include the padding and border in an element's total width and height */
* {
  box-sizing: border-box;
}

/* Remove margins and padding from the list */
ul {
  margin: 0;
  padding: 0;
}

/* Style the list items */
ul li {
  cursor: pointer;
  position: relative;
  padding: 12px 8px 12px 40px;
  list-style-type: none;
  background: #eee;
  font-size: 15px;
  transition: 0.2s;

  /* make the list items unselectable */
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}


/* Darker background-color on hover */
ul li:hover {
  background: #ddd;
}

/* When clicked on, add a background color and strike out text */
ul li.checked {
  background: #888;
  color: #fff;
  text-decoration: line-through;
}

/* Add a "checked" mark when clicked on */
ul li.checked::before {
  content: '';
  position: absolute;
  border-color: #fff;
  border-style: solid;
  border-width: 0 2px 2px 0;
  top: 10px;
  left: 16px;
  transform: rotate(45deg);
  height: 15px;
  width: 7px;
}

/* Style the close button */
.close {
  position: absolute;
  right: 0;
  top: 0;
  padding: 12px 16px 12px 16px;
}

.close:hover {
  background-color: #f44336;
  color: white;
}


/* Style the header */
.header {
  padding: 0px 0px;
  color: white;
  text-align: center;
}

/* Clear floats after the header */
.header:after {
  content: "";
  display: table;
  clear: both;
}

/* Style the input */
input {
  border: none;
  width: 90%;
  padding: 10px;
  float: left;
  font-size: 20px;
}


/* Style the "Add" button */
.addBtn {
  padding: 10px;
  width: 10%;
  background: #FFFFFF;
  color: #555;
  float: left;
  text-align: center;
  font-size: 16px;
  cursor: pointer;
  transition: 0.3s;
}

.addBtn:hover {
  background-color: #bbb;
}

#picaddbtn {
  height: auto;
  width: 100%;
  max-width: 30px;
}

</style>
<body onload="timerOne()" style="margin:0;">
<link rel="stylesheet" href="main.css">
<!-- The Loader Code -->
<div id="loader">
<div id="container" class='loading'>
     <img class="loading-gif" id="processing" src= "https://78.media.tumblr.com/a6177f6b977637597850b273022c81ed/tumblr_nurhzkuKQO1syz1nro1_500.gif"  alt="Processing" height="25%" />
     <div id='loading-text' class='loading-text'>Processing</div>
</div>
</div>
<div style="display:none;" id="myDiv" class="animate-bottom">
  <div id="myDIV" class="header">
    <span onclick="newElement()" class="addBtn"><i class="material-icons">add</i></span>
    <input type="text" id="myInput" placeholder="Add Task" height="40">
  </div>


<ul id="myUL">
  <li>Add items here</li>
  <li>Check them off when you are done</li>
  <li>You can add as much as you would like</li>
  <li>Make use of the timer below</li>
  <li>Stay Organized with Manage+</li>
</ul>
</div>
</div>
<script type='text/javascript' language='javascript' src='script.js'> </script>
</body>
</html>

JS:

// Quote generator
var strings = [
 'Only I can change my life',
 'Optimism is the faith that leads to achievement',
 'With the new day comes new strength and new thoughts',
 'Life is 10% what happens to you and 90% how you react to it',
 'Failure will never overtake me if my determination to succeed is strong enough'
];
var rand = strings[Math.floor(Math.random() * strings.length)];
document.getElementById('loading-text').innerHTML = rand;

// Loader
function timerOne() {
    myVar = setTimeout(showPage, 3000);
}

function showPage() {
  document.getElementById("loader").style.display = "none";
  document.getElementById("myDiv").style.display = "block";
}

// Create a "close" button and append it to each list item
var myNodelist = document.getElementsByTagName("LI");
var i;
for (i = 0; i < myNodelist.length; i++) {
  var span = document.createElement("SPAN");
  var txt = document.createTextNode("\u00D7");
  span.className = "close";
  span.appendChild(txt);
  myNodelist[i].appendChild(span);
}

// Click on a close button to hide the current list item
var close = document.getElementsByClassName("close");
var i;
for (i = 0; i < close.length; i++) {
  close[i].onclick = function() {
    var div = this.parentElement;
    div.style.display = "none";
  }
}

// Add a "checked" symbol when clicking on a list item
var list = document.querySelector('ul');
list.addEventListener('click', function(ev) {
  if (ev.target.tagName === 'LI') {
    ev.target.classList.toggle('checked');
  }
}, false);

// Create a new list item when clicking on the "Add" button
function newElement() {
  var li = document.createElement("li");
  var inputValue = document.getElementById("myInput").value;
  var t = document.createTextNode(inputValue);
  li.appendChild(t);
  if (inputValue === '') {
    alert("You must write something!");
  } else {
    document.getElementById("myUL").appendChild(li);
  }
  document.getElementById("myInput").value = "";

  var span = document.createElement("SPAN");
  var txt = document.createTextNode("\u00D7");
  span.className = "close";
  span.appendChild(txt);
  li.appendChild(span);

  for (i = 0; i < close.length; i++) {
    close[i].onclick = function() {
      var div = this.parentElement;
      div.style.display = "none";
    }
  }
}

清单:

   {
  "manifest_version": 2,
  "name": "Webapp",
  "version": "1.0",
  "description": "Webapp",
  "matches": ["<all_urls>"],
  "js": "script.js",
  "browser_action": {
  "default_icon": "image.png",
  "default_title": "Webapp",
  "default_popup": "webapp.html"
},
"permissions": ["tabs","activeTab"]
}

我不确定为什么代码无法正确加载。让我知道我该怎么办。 (如果可能,请发送当前代码的编辑版本。)

0 个答案:

没有答案
相关问题