質問編集履歴

1

コードの修正

2021/01/30 13:57

投稿

tetro
tetro

スコア8

test CHANGED
File without changes
test CHANGED
@@ -12,7 +12,61 @@
12
12
 
13
13
  ```JavaScript
14
14
 
15
+ 'use strict';
16
+
17
+ var settime = 900;
18
+
19
+ var min;
20
+
21
+ var sec;
22
+
23
+ var i = 0;
24
+
25
+
26
+
27
+ window.onload = function(){
28
+
29
+ i = 0;
30
+
31
+ min = 0;
32
+
33
+ sec = 0;
34
+
35
+ chrome.browserAction.setBadgeText({"text": String()})
36
+
37
+ console.log("window.onloadが読み込まれました");
38
+
39
+ }
40
+
41
+
42
+
43
+ var inter = setInterval(function(){
44
+
45
+ chrome.tabs.query( {'url': "*"}, function(tabs){
46
+
47
+ chrome.tabs.sendMessage(tabs[0].id, {message: "back -> content"}, function(item){
48
+
49
+
50
+
51
+ if(item === true){
52
+
53
+ console.log(item);
54
+
55
+ timeF();
56
+
57
+ i += 1;
58
+
59
+ }
60
+
61
+ })
62
+
63
+ })
64
+
65
+ }, 1000)
66
+
67
+
68
+
15
- var timeF = function(){
69
+ var timeF = function(){
16
70
 
17
71
  var timeinter = setInterval(function(){
18
72
 
@@ -25,6 +79,8 @@
25
79
  settime -= 1;
26
80
 
27
81
  console.log(min + ":" + sec);
82
+
83
+ chrome.browserAction.setBadgeText({"text": String(settime)});
28
84
 
29
85
 
30
86
 
@@ -44,13 +100,15 @@
44
100
 
45
101
  if(settime < 0){
46
102
 
47
- console.log("計測終了");
103
+ console.log("計測終了");
48
104
 
49
105
  clearInterval(timeinter);
50
106
 
51
107
  settime = 900;
52
108
 
53
109
  i = 0;
110
+
111
+ chrome.browserAction.setBadgeText({"text": String()})
54
112
 
55
113
  }
56
114
 
@@ -62,4 +120,24 @@
62
120
 
63
121
  }
64
122
 
123
+
124
+
125
+ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse){
126
+
127
+ if(request.message === "i want min"){
128
+
129
+ sendResponse(min);
130
+
131
+ }
132
+
133
+
134
+
135
+ if(request.message === "i want sec"){
136
+
137
+ sendResponse(sec);
138
+
139
+ }
140
+
141
+ });
142
+
65
143
  ```