質問編集履歴

3

不足情報の追加をしました

2019/01/18 14:24

投稿

emble
emble

スコア8

test CHANGED
File without changes
test CHANGED
@@ -32,7 +32,7 @@
32
32
 
33
33
  Screen.height = Body.getPlayer().clientHeight
34
34
 
35
- console.log(Screen.width)//ここはちゃんと表示される
35
+ console.log(Screen.width)//ちゃんと表示される
36
36
 
37
37
  },
38
38
 
@@ -44,7 +44,7 @@
44
44
 
45
45
  MyApp.updatePlayerStatus()
46
46
 
47
- console.log(Screen.width)//0にな
47
+ console.log(Screen.width)//ちゃんと表示され
48
48
 
49
49
  }
50
50
 
@@ -55,3 +55,67 @@
55
55
  おそらく別の場所でScreen.widthを使うと、値を持ってきただけで大元が変わるわけではないのだろうなぁなどと考え、宣言する場所を変えたりしてみましたが結果は変わらず、改善策が思いつきません。
56
56
 
57
57
  どうすれば最初のScreen.width自体を変えることができるかご教示頂きたいです。
58
+
59
+
60
+
61
+ ###追記
62
+
63
+ このコードはTampermonkeyでTwitchの配信視聴ページ(https://www.twitch.tv/ユーザー名)向けのスクリプトを書いた時のものです。一番重要な部分を書き忘れていました。申し訳ございません。
64
+
65
+ 色々と試してみた結果、window.onloadではなく以下の様な方法で実行させると現象が起きました。
66
+
67
+ ```Javascript
68
+
69
+ var Body = {
70
+
71
+ getPlayer: function(){return document.getElementsByClassName('player-video')[0]}
72
+
73
+ }
74
+
75
+
76
+
77
+ var Screen = {}
78
+
79
+ Screen.width = 0
80
+
81
+ Screen.height = 0
82
+
83
+
84
+
85
+ var MyApp = {
86
+
87
+ updatePlayerStatus: function(){
88
+
89
+ Screen.width = Body.getPlayer().clientWidth
90
+
91
+ Screen.height = Body.getPlayer().clientHeight
92
+
93
+ console.log(Screen.width)//正しく表示される
94
+
95
+ },
96
+
97
+ }
98
+
99
+ ////プレイヤーが読み込まれたら実行
100
+
101
+ let retry_count=0
102
+
103
+ var waitLoading = setInterval(function(){
104
+
105
+ retry_count++
106
+
107
+ if(retry_count > 10)clearInterval(waitLoading)
108
+
109
+ if(Body.getPlayer()!==undefined){
110
+
111
+ MyApp.updatePlayerStatus()
112
+
113
+ console.log(Screen.height)//0
114
+
115
+ clearInterval(waitLoading)
116
+
117
+ }
118
+
119
+ }, 1000)
120
+
121
+ ```

2

ソースコードの誤字を直しました

2019/01/18 14:24

投稿

emble
emble

スコア8

test CHANGED
File without changes
test CHANGED
@@ -40,7 +40,7 @@
40
40
 
41
41
 
42
42
 
43
- windows.onload = function(){
43
+ window.onload = function(){
44
44
 
45
45
  MyApp.updatePlayerStatus()
46
46
 

1

初心者アイコンつけ忘れました

2019/01/18 13:19

投稿

emble
emble

スコア8

test CHANGED
File without changes
test CHANGED
File without changes