Rev 915 | Blame | Compare with Previous | Last modification | View Log | RSS feed
//debug modewindow.debug=true;//window.debug=false;//檢查是否支援 Storagefunction checkStorageSupport(){//支援if(typeof(Storage) !== undefined){//debugconsole.log('Web Storage supported');//回傳 "true"return true;}//if endelse{//debugconsole.log('Sorry! No Web Storage support..');//回傳 "false"return false;}//else end}//function checkStorageSupport end//get img or video snapshotfunction getImgAndVideoSnapshotPreview(){return document.querySelectorAll('div > div > span.img');}//function getImgAndVideoSnapshotPreview end//get all posted ima and videofunction getAllPostedImgAndVideo(){document.querySelectorAll('span.img._tl_article_media_viewer');}//funtion getAllPostefImgAndVideo//get all posted textfunction getAllpostedText(){document.querySelectorAll('div.article_contents > p.type_text');}//function getAllpostedText end//post test & image & video 2 youtubefunction post2youtube(){//debugconsole.log('post2youtube');//put video//put text//put img url}//function post2youtube end//query upload img and video snapshotfunction getImgAndVideoSnapshot(){//回傳抓去到的照片與影片截圖return document.querySelectorAll('div > div._drags > span.img');}//function getImgAndVideoSnapshot end//post test & image & video 2 fbfunction post2FB(){//debugif(window.debug) console.log('post2FB');//put video url//put text//put img url}//function post2FB end//post test & image & video 2 pixnetfunction post2pixnet(){//debugif(window.debug) console.log('post2pixnet');//put video url//put text//put img url}//function post2pixnet end//當按下新增影片時,要做的事情。function selectVideoEvent(){}//function selectVideoEvent end//當編輯好文章內容,按下發布按鈕時要做的事情。function post_event(){//取得post訊息的按鈕btn_post=document.getElementsByClassName('btn_post');//debugif(window.debug) console.log(btn_post);//當按下 post 時btn_post[0].addEventListener('click',function(event){//debugif(window.debug) console.log('preventDefault & stopPropagation');//disable default event actionevent.preventDefault();//disbale event propagationevent.stopPropagation();//debugif(window.debug) console.log('clicked');//取得要發布的內文區段post_conetent_section=document.getElementsByClassName('write_post _tl_write_post');//debugif(window.debug) console.log(post_conetent_section);//取得發布的網頁文字內容post_conetent_html=post_conetent_section[0].children[1].children[0].innerHTML;//debugif(window.debug) console.log(post_conetent_html);//debugif(window.debug) console.log(localStorage.qbpwcf);//debugif(window.debug) console.log(JSON.parse(localStorage.qbpwcf));//從 storage 取出 qbpwcfqbpwcf=JSON.parse(localStorage.qbpwcf);//儲存發布的網頁文字內容qbpwcf.Extention.LineTimeline.html=post_conetent_html;//debugif(window.debug) console.log(qbpwcf.Extention.LineTimeline.html);//將 qbpwcf 儲存到 storagelocalStorage.qbpwcf=JSON.stringify(qbpwcf);//debugif(window.debug) console.log(localStorage.qbpwcf);//debugif(window.debug) console.log(JSON.parse(localStorage.qbpwcf));//取得發布的文字內容post_conetent_text=post_conetent_section[0].children[1].children[0].innerText;//debugif(window.debug) console.log(post_conetent_text);//debugif(window.debug) console.log(JSON.parse(localStorage.qbpwcf));//從 storage 取出 qbpwcfqbpwcf=JSON.parse(localStorage.qbpwcf);//儲存發布的文字內容qbpwcf.Extention.LineTimeline.text=post_conetent_text;//debugif(window.debug) console.log(qbpwcf.Extention.LineTimeline.text);//將 qbpwcf 儲存到 storagelocalStorage.qbpwcf=JSON.stringify(qbpwcf);//debugif(window.debug) console.log(localStorage.qbpwcf);//如果該區段有照片if(post_content_image_section=document.getElementsByClassName('media_grid imgtype_grid').length!==0){//取得圖片的區域post_content_image_section=document.getElementsByClassName('media_grid imgtype_grid')[0].children;//debugif(window.debug) console.log(post_content_image_section);//取得圖片的區域有多少張照片post_content_image_section_length=post_content_image_section.length//debugif(window.debug) console.log(post_content_image_section_length);//依照每張照片for(i=0;i<post_content_image_section_length;i++){//debugif(window.debug) console.log(post_content_image_section[i]);//debugif(window.debug) console.log(post_content_image_section[i].children[0].style.backgroundImage);//debugif(window.debug) console.log(post_content_image_section[i].children[0].style.backgroundImage.split('url(\"'));//debugif(window.debug) console.log(post_content_image_section[i].children[0].style.backgroundImage.split('url(\"')[1].split('\")'));//debugif(window.debug) console.log(post_content_image_section[i].children[0].style.backgroundImage.split('url(\"')[1].split('\")')[0]);//從 storage 取出 qbpwcfqbpwcf=JSON.parse(localStorage.qbpwcf);//儲存照片qbpwcf.Extention.LineTimeline.img.push(post_content_image_section[i].children[0].style.backgroundImage.split('url(\"')[1].split('\")')[0]);//debugif(window.debug) console.log(qbpwcf.Extention.LineTimeline.img);//將 qbpwcf 儲存到 storagelocalStorage.qbpwcf=JSON.stringify(qbpwcf);//debugif(window.debug) console.log(localStorage.qbpwcf);}//for end}//if end//post to youtubepost2youtube();//post to fbpost2FB();//post to pixnetpost2pixnet();//init local storageinitLocalStorage();});//addEventListen end}//function post_evevt end//function show share button eventfunction showShareBtnEvent(){//debugif(window.debug) console.log('enter function showShareBtnEvent');//取得文章列表articles=document.querySelectorAll('article');//debugif(window.debug) console.log(articles);//set start pointi=0;//針對每個文章while(i<articles.length){//debugif(window.debug) console.log(i);//取得index數值的內容index=Object.assign({},{i});//debugif(window.debug) console.log(index);//debugif(window.debug) console.log(index.i.valueOf());//取得index的數值index=index.i.valueOf();//debugif(window.debug) console.log(index);//debugif(window.debug) console.log(articles);//debugif(window.debug) console.log(articles[index]);//從 storage 取出 qbpwcfqbpwcf=JSON.parse(localStorage.qbpwcf);//儲存for的indexqbpwcf.Extention.LineTimeline.forIndex=index;//debugif(window.debug) console.log(qbpwcf.Extention.LineTimeline.forIndex);//將 qbpwcf 儲存到 storagelocalStorage.qbpwcf=JSON.stringify(qbpwcf);//debugif(window.debug) console.log(localStorage.qbpwcf);//增加滑鼠移動進取後要出現後觸發事件articles[index].addEventListener('mouseover',function(event){//debugif(window.debug) console.log('enter mouseover event');//debugif(window.debug) console.log(event);//get event trigger elementelementTrigger=event.target;//如果不是 article tagwhile(elementTrigger.nodeName!=='ARTICLE'){//取得上層元素elementTrigger=elementTrigger.parentElement;}//while end//從 storage 取出 qbpwcfqbpwcf=JSON.parse(localStorage.qbpwcf);//debugif(window.debug) console.log(qbpwcf);//儲存for的indexi=qbpwcf.Extention.LineTimeline.forIndex;//debugif(window.debug) console.log(i);//取得index數值的內容index=Object.assign({},i);//debugif(window.debug) console.log(index);//create notify text nodetext=document.createTextNode('Click me to Post to FB & Youtube & Pixnet~ ');//create notify spannotify_span=document.createElement('span');//put notify to spannotify_span.appendChild(text);//create notify anotify_a=document.createElement('a');//create notify hrefnotify_a.href="#";//prevent click eventnotify_a.onclick=function(e){e.preventDefault();//get content//debugif(window.debug) console.log('get post content');//save to localStorage//debugif(window.debug) console.log('save to localStorage');//scroll to top//debugif(window.debug) console.log('scroll to top');//click write new post//debugif(window.debug) console.log('click write new post');}//put notify_span to notify_anotify_a.appendChild(notify_span);//create ad text nodetext=document.createTextNode('Powered by QBPWCF!');//create ad spanad_span=document.createElement('span');//red color fontad_span.style.color='red';//put ad to spanad_span.appendChild(text);//create div nodediv=document.createElement('div');//將 span 內容放進 div 裡面div.appendChild(notify_a);div.appendChild(ad_span);//背景顏色div.style.backgroundColor='#CCCCFF';//debugif(window.debug) console.log(div);//debugif(window.debug) console.log(document);//debugif(window.debug) console.log(elementTrigger.firstChild.firstChild.textContent);if(window.debug) console.log(div.firstChild.textContent);if(window.debug) console.log(elementTrigger.firstChild.firstChild.textContent==div.firstChild.textContent);//如果沒有提示文字if(elementTrigger.firstChild.firstChild.textContent!==div.firstChild.textContent){//debugif(window.debug) console.log('no tool text');//將提示內容放到標題上方elementTrigger.prepend(div);//debugif(window.debug) console.log(elementTrigger.firstChild);}//if end});//articles event end//step +1i++;}//while end}//function showShareBtnEvent end//function share button clcik eventfunction shareBtnClickEvent(){//get text//get img//get video}//function shareBtnClickEvent end//init local storagefunction initLocalStorage(){//json strucqbpwcf={Extention:{LineTimeline:{//texttext:"",//htmlhtml:"",//imgimg:[],//videovideo:[]}}}//initil storagelocalStorage.qbpwcf=JSON.stringify(qbpwcf);}//function initLocationStorage end//debugconsole.log('found target url');//on readysetTimeout(function(){window.addEventListener('load', function(event){//debugconsole.log('All resources finished loading!');if(checkStorageSupport()===true){//init local storageinitLocalStorage();//bind post eventpost_event();//show share button eventshowShareBtnEvent();//bind click for share eventshareBtnClickEvent();}//if end});},1);