| 1 |
liveuser |
1 |
//debug mode
|
|
|
2 |
window.debug=true;
|
|
|
3 |
//window.debug=false;
|
|
|
4 |
|
|
|
5 |
//檢查是否支援 Storage
|
|
|
6 |
function checkStorageSupport(){
|
|
|
7 |
|
|
|
8 |
//支援
|
|
|
9 |
if(typeof(Storage) !== undefined){
|
|
|
10 |
|
|
|
11 |
//debug
|
|
|
12 |
console.log('Web Storage supported');
|
|
|
13 |
|
|
|
14 |
//回傳 "true"
|
|
|
15 |
return true;
|
|
|
16 |
|
|
|
17 |
}//if end
|
|
|
18 |
|
|
|
19 |
else{
|
|
|
20 |
|
|
|
21 |
//debug
|
|
|
22 |
console.log('Sorry! No Web Storage support..');
|
|
|
23 |
|
|
|
24 |
//回傳 "false"
|
|
|
25 |
return false;
|
|
|
26 |
|
|
|
27 |
}//else end
|
|
|
28 |
|
|
|
29 |
}//function checkStorageSupport end
|
|
|
30 |
|
|
|
31 |
//get img or video snapshot
|
|
|
32 |
function getImgAndVideoSnapshotPreview(){
|
|
|
33 |
|
|
|
34 |
return document.querySelectorAll('div > div > span.img');
|
|
|
35 |
|
|
|
36 |
}//function getImgAndVideoSnapshotPreview end
|
|
|
37 |
|
|
|
38 |
//get all posted ima and video
|
|
|
39 |
function getAllPostedImgAndVideo(){
|
|
|
40 |
|
|
|
41 |
document.querySelectorAll('span.img._tl_article_media_viewer');
|
|
|
42 |
|
|
|
43 |
}//funtion getAllPostefImgAndVideo
|
|
|
44 |
|
|
|
45 |
//get all posted text
|
|
|
46 |
function getAllpostedText(){
|
|
|
47 |
|
|
|
48 |
document.querySelectorAll('div.article_contents > p.type_text');
|
|
|
49 |
|
|
|
50 |
}//function getAllpostedText end
|
|
|
51 |
|
|
|
52 |
//post test & image & video 2 youtube
|
|
|
53 |
function post2youtube(){
|
|
|
54 |
|
|
|
55 |
//debug
|
|
|
56 |
console.log('post2youtube');
|
|
|
57 |
|
|
|
58 |
//put video
|
|
|
59 |
|
|
|
60 |
//put text
|
|
|
61 |
|
|
|
62 |
//put img url
|
|
|
63 |
|
|
|
64 |
}//function post2youtube end
|
|
|
65 |
|
|
|
66 |
//query upload img and video snapshot
|
|
|
67 |
function getImgAndVideoSnapshot(){
|
|
|
68 |
|
|
|
69 |
//回傳抓去到的照片與影片截圖
|
|
|
70 |
return document.querySelectorAll('div > div._drags > span.img');
|
|
|
71 |
|
|
|
72 |
}//function getImgAndVideoSnapshot end
|
|
|
73 |
|
|
|
74 |
//post test & image & video 2 fb
|
|
|
75 |
function post2FB(){
|
|
|
76 |
|
|
|
77 |
//debug
|
|
|
78 |
if(window.debug) console.log('post2FB');
|
|
|
79 |
|
|
|
80 |
//put video url
|
|
|
81 |
|
|
|
82 |
//put text
|
|
|
83 |
|
|
|
84 |
//put img url
|
|
|
85 |
|
|
|
86 |
}//function post2FB end
|
|
|
87 |
|
|
|
88 |
//post test & image & video 2 pixnet
|
|
|
89 |
function post2pixnet(){
|
|
|
90 |
|
|
|
91 |
//debug
|
|
|
92 |
if(window.debug) console.log('post2pixnet');
|
|
|
93 |
|
|
|
94 |
//put video url
|
|
|
95 |
|
|
|
96 |
//put text
|
|
|
97 |
|
|
|
98 |
//put img url
|
|
|
99 |
|
|
|
100 |
}//function post2pixnet end
|
|
|
101 |
|
|
|
102 |
//當按下新增影片時,要做的事情。
|
|
|
103 |
function selectVideoEvent(){
|
|
|
104 |
|
|
|
105 |
|
|
|
106 |
|
|
|
107 |
}//function selectVideoEvent end
|
|
|
108 |
|
|
|
109 |
//當編輯好文章內容,按下發布按鈕時要做的事情。
|
|
|
110 |
function post_event(){
|
|
|
111 |
|
|
|
112 |
//取得post訊息的按鈕
|
|
|
113 |
btn_post=document.getElementsByClassName('btn_post');
|
|
|
114 |
|
|
|
115 |
//debug
|
|
|
116 |
if(window.debug) console.log(btn_post);
|
|
|
117 |
|
|
|
118 |
//當按下 post 時
|
|
|
119 |
btn_post[0].addEventListener('click',function(event){
|
|
|
120 |
|
|
|
121 |
//debug
|
|
|
122 |
if(window.debug) console.log('preventDefault & stopPropagation');
|
|
|
123 |
|
|
|
124 |
//disable default event action
|
|
|
125 |
event.preventDefault();
|
|
|
126 |
|
|
|
127 |
//disbale event propagation
|
|
|
128 |
event.stopPropagation();
|
|
|
129 |
|
|
|
130 |
//debug
|
|
|
131 |
if(window.debug) console.log('clicked');
|
|
|
132 |
|
|
|
133 |
//取得要發布的內文區段
|
|
|
134 |
post_conetent_section=document.getElementsByClassName('write_post _tl_write_post');
|
|
|
135 |
|
|
|
136 |
//debug
|
|
|
137 |
if(window.debug) console.log(post_conetent_section);
|
|
|
138 |
|
|
|
139 |
//取得發布的網頁文字內容
|
|
|
140 |
post_conetent_html=post_conetent_section[0].children[1].children[0].innerHTML;
|
|
|
141 |
|
|
|
142 |
//debug
|
|
|
143 |
if(window.debug) console.log(post_conetent_html);
|
|
|
144 |
|
|
|
145 |
//debug
|
|
|
146 |
if(window.debug) console.log(localStorage.qbpwcf);
|
|
|
147 |
|
|
|
148 |
//debug
|
|
|
149 |
if(window.debug) console.log(JSON.parse(localStorage.qbpwcf));
|
|
|
150 |
|
|
|
151 |
//從 storage 取出 qbpwcf
|
|
|
152 |
qbpwcf=JSON.parse(localStorage.qbpwcf);
|
|
|
153 |
|
|
|
154 |
//儲存發布的網頁文字內容
|
|
|
155 |
qbpwcf.Extention.LineTimeline.html=post_conetent_html;
|
|
|
156 |
|
|
|
157 |
//debug
|
|
|
158 |
if(window.debug) console.log(qbpwcf.Extention.LineTimeline.html);
|
|
|
159 |
|
|
|
160 |
//將 qbpwcf 儲存到 storage
|
|
|
161 |
localStorage.qbpwcf=JSON.stringify(qbpwcf);
|
|
|
162 |
|
|
|
163 |
//debug
|
|
|
164 |
if(window.debug) console.log(localStorage.qbpwcf);
|
|
|
165 |
|
|
|
166 |
//debug
|
|
|
167 |
if(window.debug) console.log(JSON.parse(localStorage.qbpwcf));
|
|
|
168 |
|
|
|
169 |
//取得發布的文字內容
|
|
|
170 |
post_conetent_text=post_conetent_section[0].children[1].children[0].innerText;
|
|
|
171 |
|
|
|
172 |
//debug
|
|
|
173 |
if(window.debug) console.log(post_conetent_text);
|
|
|
174 |
|
|
|
175 |
//debug
|
|
|
176 |
if(window.debug) console.log(JSON.parse(localStorage.qbpwcf));
|
|
|
177 |
|
|
|
178 |
//從 storage 取出 qbpwcf
|
|
|
179 |
qbpwcf=JSON.parse(localStorage.qbpwcf);
|
|
|
180 |
|
|
|
181 |
//儲存發布的文字內容
|
|
|
182 |
qbpwcf.Extention.LineTimeline.text=post_conetent_text;
|
|
|
183 |
|
|
|
184 |
//debug
|
|
|
185 |
if(window.debug) console.log(qbpwcf.Extention.LineTimeline.text);
|
|
|
186 |
|
|
|
187 |
//將 qbpwcf 儲存到 storage
|
|
|
188 |
localStorage.qbpwcf=JSON.stringify(qbpwcf);
|
|
|
189 |
|
|
|
190 |
//debug
|
|
|
191 |
if(window.debug) console.log(localStorage.qbpwcf);
|
|
|
192 |
|
|
|
193 |
//如果該區段有照片
|
|
|
194 |
if(post_content_image_section=document.getElementsByClassName('media_grid imgtype_grid').length!==0){
|
|
|
195 |
|
|
|
196 |
//取得圖片的區域
|
|
|
197 |
post_content_image_section=document.getElementsByClassName('media_grid imgtype_grid')[0].children;
|
|
|
198 |
|
|
|
199 |
//debug
|
|
|
200 |
if(window.debug) console.log(post_content_image_section);
|
|
|
201 |
|
|
|
202 |
//取得圖片的區域有多少張照片
|
|
|
203 |
post_content_image_section_length=post_content_image_section.length
|
|
|
204 |
|
|
|
205 |
//debug
|
|
|
206 |
if(window.debug) console.log(post_content_image_section_length);
|
|
|
207 |
|
|
|
208 |
//依照每張照片
|
|
|
209 |
for(i=0;i<post_content_image_section_length;i++){
|
|
|
210 |
|
|
|
211 |
//debug
|
|
|
212 |
if(window.debug) console.log(post_content_image_section[i]);
|
|
|
213 |
|
|
|
214 |
//debug
|
|
|
215 |
if(window.debug) console.log(post_content_image_section[i].children[0].style.backgroundImage);
|
|
|
216 |
|
|
|
217 |
//debug
|
|
|
218 |
if(window.debug) console.log(post_content_image_section[i].children[0].style.backgroundImage.split('url(\"'));
|
|
|
219 |
|
|
|
220 |
//debug
|
|
|
221 |
if(window.debug) console.log(post_content_image_section[i].children[0].style.backgroundImage.split('url(\"')[1].split('\")'));
|
|
|
222 |
|
|
|
223 |
//debug
|
|
|
224 |
if(window.debug) console.log(post_content_image_section[i].children[0].style.backgroundImage.split('url(\"')[1].split('\")')[0]);
|
|
|
225 |
|
|
|
226 |
//從 storage 取出 qbpwcf
|
|
|
227 |
qbpwcf=JSON.parse(localStorage.qbpwcf);
|
|
|
228 |
|
|
|
229 |
//儲存照片
|
|
|
230 |
qbpwcf.Extention.LineTimeline.img.push(post_content_image_section[i].children[0].style.backgroundImage.split('url(\"')[1].split('\")')[0]);
|
|
|
231 |
|
|
|
232 |
//debug
|
|
|
233 |
if(window.debug) console.log(qbpwcf.Extention.LineTimeline.img);
|
|
|
234 |
|
|
|
235 |
//將 qbpwcf 儲存到 storage
|
|
|
236 |
localStorage.qbpwcf=JSON.stringify(qbpwcf);
|
|
|
237 |
|
|
|
238 |
//debug
|
|
|
239 |
if(window.debug) console.log(localStorage.qbpwcf);
|
|
|
240 |
|
|
|
241 |
}//for end
|
|
|
242 |
|
|
|
243 |
}//if end
|
|
|
244 |
|
|
|
245 |
//post to youtube
|
|
|
246 |
post2youtube();
|
|
|
247 |
|
|
|
248 |
//post to fb
|
|
|
249 |
post2FB();
|
|
|
250 |
|
|
|
251 |
//post to pixnet
|
|
|
252 |
post2pixnet();
|
|
|
253 |
|
|
|
254 |
//init local storage
|
|
|
255 |
initLocalStorage();
|
|
|
256 |
|
|
|
257 |
});//addEventListen end
|
|
|
258 |
|
|
|
259 |
}//function post_evevt end
|
|
|
260 |
|
|
|
261 |
//function show share button event
|
|
|
262 |
function showShareBtnEvent(){
|
|
|
263 |
|
|
|
264 |
//debug
|
|
|
265 |
if(window.debug) console.log('enter function showShareBtnEvent');
|
|
|
266 |
|
|
|
267 |
//取得文章列表
|
|
|
268 |
articles=document.querySelectorAll('article');
|
|
|
269 |
|
|
|
270 |
//debug
|
|
|
271 |
if(window.debug) console.log(articles);
|
|
|
272 |
|
|
|
273 |
//set start point
|
|
|
274 |
i=0;
|
|
|
275 |
|
|
|
276 |
//針對每個文章
|
|
|
277 |
while(i<articles.length){
|
|
|
278 |
|
|
|
279 |
//debug
|
|
|
280 |
if(window.debug) console.log(i);
|
|
|
281 |
|
|
|
282 |
//取得index數值的內容
|
|
|
283 |
index=Object.assign({},{i});
|
|
|
284 |
|
|
|
285 |
//debug
|
|
|
286 |
if(window.debug) console.log(index);
|
|
|
287 |
|
|
|
288 |
//debug
|
|
|
289 |
if(window.debug) console.log(index.i.valueOf());
|
|
|
290 |
|
|
|
291 |
//取得index的數值
|
|
|
292 |
index=index.i.valueOf();
|
|
|
293 |
|
|
|
294 |
//debug
|
|
|
295 |
if(window.debug) console.log(index);
|
|
|
296 |
|
|
|
297 |
//debug
|
|
|
298 |
if(window.debug) console.log(articles);
|
|
|
299 |
|
|
|
300 |
//debug
|
|
|
301 |
if(window.debug) console.log(articles[index]);
|
|
|
302 |
|
|
|
303 |
//從 storage 取出 qbpwcf
|
|
|
304 |
qbpwcf=JSON.parse(localStorage.qbpwcf);
|
|
|
305 |
|
|
|
306 |
//儲存for的index
|
|
|
307 |
qbpwcf.Extention.LineTimeline.forIndex=index;
|
|
|
308 |
|
|
|
309 |
//debug
|
|
|
310 |
if(window.debug) console.log(qbpwcf.Extention.LineTimeline.forIndex);
|
|
|
311 |
|
|
|
312 |
//將 qbpwcf 儲存到 storage
|
|
|
313 |
localStorage.qbpwcf=JSON.stringify(qbpwcf);
|
|
|
314 |
|
|
|
315 |
//debug
|
|
|
316 |
if(window.debug) console.log(localStorage.qbpwcf);
|
|
|
317 |
|
|
|
318 |
//增加滑鼠移動進取後要出現後觸發事件
|
|
|
319 |
articles[index].addEventListener('mouseover',function(event){
|
|
|
320 |
|
|
|
321 |
//debug
|
|
|
322 |
if(window.debug) console.log('enter mouseover event');
|
|
|
323 |
|
|
|
324 |
//debug
|
|
|
325 |
if(window.debug) console.log(event);
|
|
|
326 |
|
|
|
327 |
//get event trigger element
|
|
|
328 |
elementTrigger=event.target;
|
|
|
329 |
|
|
|
330 |
//如果不是 article tag
|
|
|
331 |
while(elementTrigger.nodeName!=='ARTICLE'){
|
|
|
332 |
|
|
|
333 |
//取得上層元素
|
|
|
334 |
elementTrigger=elementTrigger.parentElement;
|
|
|
335 |
|
|
|
336 |
}//while end
|
|
|
337 |
|
|
|
338 |
//從 storage 取出 qbpwcf
|
|
|
339 |
qbpwcf=JSON.parse(localStorage.qbpwcf);
|
|
|
340 |
|
|
|
341 |
//debug
|
|
|
342 |
if(window.debug) console.log(qbpwcf);
|
|
|
343 |
|
|
|
344 |
//儲存for的index
|
|
|
345 |
i=qbpwcf.Extention.LineTimeline.forIndex;
|
|
|
346 |
|
|
|
347 |
//debug
|
|
|
348 |
if(window.debug) console.log(i);
|
|
|
349 |
|
|
|
350 |
//取得index數值的內容
|
|
|
351 |
index=Object.assign({},i);
|
|
|
352 |
|
|
|
353 |
//debug
|
|
|
354 |
if(window.debug) console.log(index);
|
|
|
355 |
|
|
|
356 |
//create notify text node
|
|
|
357 |
text=document.createTextNode('Click me to Post to FB & Youtube & Pixnet~ ');
|
|
|
358 |
|
|
|
359 |
//create notify span
|
|
|
360 |
notify_span=document.createElement('span');
|
|
|
361 |
|
|
|
362 |
//put notify to span
|
|
|
363 |
notify_span.appendChild(text);
|
|
|
364 |
|
|
|
365 |
//create notify a
|
|
|
366 |
notify_a=document.createElement('a');
|
|
|
367 |
|
|
|
368 |
//create notify href
|
|
|
369 |
notify_a.href="#";
|
|
|
370 |
|
|
|
371 |
//prevent click event
|
|
|
372 |
notify_a.onclick=function(e){
|
|
|
373 |
|
|
|
374 |
e.preventDefault();
|
|
|
375 |
|
|
|
376 |
//get content
|
|
|
377 |
|
|
|
378 |
//debug
|
|
|
379 |
if(window.debug) console.log('get post content');
|
|
|
380 |
|
|
|
381 |
//save to localStorage
|
|
|
382 |
|
|
|
383 |
//debug
|
|
|
384 |
if(window.debug) console.log('save to localStorage');
|
|
|
385 |
|
|
|
386 |
//scroll to top
|
|
|
387 |
|
|
|
388 |
//debug
|
|
|
389 |
if(window.debug) console.log('scroll to top');
|
|
|
390 |
|
|
|
391 |
//click write new post
|
|
|
392 |
|
|
|
393 |
//debug
|
|
|
394 |
if(window.debug) console.log('click write new post');
|
|
|
395 |
|
|
|
396 |
}
|
|
|
397 |
|
|
|
398 |
//put notify_span to notify_a
|
|
|
399 |
notify_a.appendChild(notify_span);
|
|
|
400 |
|
|
|
401 |
//create ad text node
|
|
|
402 |
text=document.createTextNode('Powered by QBPWCF!');
|
|
|
403 |
|
|
|
404 |
//create ad span
|
|
|
405 |
ad_span=document.createElement('span');
|
|
|
406 |
|
|
|
407 |
//red color font
|
|
|
408 |
ad_span.style.color='red';
|
|
|
409 |
|
|
|
410 |
//put ad to span
|
|
|
411 |
ad_span.appendChild(text);
|
|
|
412 |
|
|
|
413 |
//create div node
|
|
|
414 |
div=document.createElement('div');
|
|
|
415 |
|
|
|
416 |
//將 span 內容放進 div 裡面
|
|
|
417 |
div.appendChild(notify_a);
|
|
|
418 |
div.appendChild(ad_span);
|
|
|
419 |
|
|
|
420 |
//背景顏色
|
|
|
421 |
div.style.backgroundColor='#CCCCFF';
|
|
|
422 |
|
|
|
423 |
//debug
|
|
|
424 |
if(window.debug) console.log(div);
|
|
|
425 |
|
|
|
426 |
//debug
|
|
|
427 |
if(window.debug) console.log(document);
|
|
|
428 |
|
|
|
429 |
//debug
|
|
|
430 |
if(window.debug) console.log(elementTrigger.firstChild.firstChild.textContent);
|
|
|
431 |
if(window.debug) console.log(div.firstChild.textContent);
|
|
|
432 |
if(window.debug) console.log(elementTrigger.firstChild.firstChild.textContent==div.firstChild.textContent);
|
|
|
433 |
|
|
|
434 |
//如果沒有提示文字
|
|
|
435 |
if(elementTrigger.firstChild.firstChild.textContent!==div.firstChild.textContent){
|
|
|
436 |
|
|
|
437 |
//debug
|
|
|
438 |
if(window.debug) console.log('no tool text');
|
|
|
439 |
|
|
|
440 |
//將提示內容放到標題上方
|
|
|
441 |
elementTrigger.prepend(div);
|
|
|
442 |
|
|
|
443 |
//debug
|
|
|
444 |
if(window.debug) console.log(elementTrigger.firstChild);
|
|
|
445 |
|
|
|
446 |
}//if end
|
|
|
447 |
|
|
|
448 |
});//articles event end
|
|
|
449 |
|
|
|
450 |
//step +1
|
|
|
451 |
i++;
|
|
|
452 |
|
|
|
453 |
}//while end
|
|
|
454 |
|
|
|
455 |
}//function showShareBtnEvent end
|
|
|
456 |
|
|
|
457 |
//function share button clcik event
|
|
|
458 |
function shareBtnClickEvent(){
|
|
|
459 |
|
|
|
460 |
//get text
|
|
|
461 |
|
|
|
462 |
//get img
|
|
|
463 |
|
|
|
464 |
//get video
|
|
|
465 |
|
|
|
466 |
}//function shareBtnClickEvent end
|
|
|
467 |
|
|
|
468 |
//init local storage
|
|
|
469 |
function initLocalStorage(){
|
|
|
470 |
|
|
|
471 |
//json struc
|
|
|
472 |
qbpwcf={
|
|
|
473 |
|
|
|
474 |
Extention:{
|
|
|
475 |
|
|
|
476 |
LineTimeline:{
|
|
|
477 |
|
|
|
478 |
//text
|
|
|
479 |
text:"",
|
|
|
480 |
|
|
|
481 |
//html
|
|
|
482 |
html:"",
|
|
|
483 |
|
|
|
484 |
//img
|
|
|
485 |
img:[],
|
|
|
486 |
|
|
|
487 |
//video
|
|
|
488 |
video:[]
|
|
|
489 |
|
|
|
490 |
}
|
|
|
491 |
}
|
|
|
492 |
}
|
|
|
493 |
|
|
|
494 |
//initil storage
|
|
|
495 |
localStorage.qbpwcf=JSON.stringify(qbpwcf);
|
|
|
496 |
|
|
|
497 |
}//function initLocationStorage end
|
|
|
498 |
|
|
|
499 |
//debug
|
|
|
500 |
console.log('found target url');
|
|
|
501 |
|
|
|
502 |
//on ready
|
|
|
503 |
setTimeout(function(){
|
|
|
504 |
|
|
|
505 |
window.addEventListener('load', function(event){
|
|
|
506 |
|
|
|
507 |
//debug
|
|
|
508 |
console.log('All resources finished loading!');
|
|
|
509 |
|
|
|
510 |
if(checkStorageSupport()===true){
|
|
|
511 |
|
|
|
512 |
//init local storage
|
|
|
513 |
initLocalStorage();
|
|
|
514 |
|
|
|
515 |
//bind post event
|
|
|
516 |
post_event();
|
|
|
517 |
|
|
|
518 |
//show share button event
|
|
|
519 |
showShareBtnEvent();
|
|
|
520 |
|
|
|
521 |
//bind click for share event
|
|
|
522 |
shareBtnClickEvent();
|
|
|
523 |
|
|
|
524 |
}//if end
|
|
|
525 |
|
|
|
526 |
});
|
|
|
527 |
|
|
|
528 |
},1);
|