Subversion Repositories qbpwcf-lib(archive)

Rev

Rev 911 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

//debug mode
window.debug=true;
//window.debug=false;

//檢查是否支援 Storage
function checkStorageSupport(){

  //支援
  if(typeof(Storage) !== undefined){

                //debug
                console.log('Web Storage supported');

                //回傳 "true"
                return true;

                }//if end

  else{

    //debug
    console.log('Sorry! No Web Storage support..');

                //回傳 "false"
                return false;

          }//else end

  }//function checkStorageSupport end

//get img or video snapshot
function getImgAndVideoSnapshotPreview(){

  return document.querySelectorAll('div > div > span.img');

  }//function getImgAndVideoSnapshotPreview end

//get all posted ima and video
function getAllPostedImgAndVideo(){

  document.querySelectorAll('span.img._tl_article_media_viewer');

  }//funtion getAllPostefImgAndVideo

//get all posted text
function getAllpostedText(){

  document.querySelectorAll('div.article_contents > p.type_text');

  }//function getAllpostedText end

//post test & image & video 2 youtube
function post2youtube(){

  //debug
  console.log('post2youtube');

  //put video

  //put text

  //put img url

  }//function post2youtube end

//query upload img and video snapshot
function getImgAndVideoSnapshot(){

  //回傳抓去到的照片與影片截圖
  return document.querySelectorAll('div > div._drags > span.img');

  }//function getImgAndVideoSnapshot end

//post test & image & video 2 fb
function post2FB(){

  //debug
  if(window.debug) console.log('post2FB');

  //put video url

  //put text

  //put img url

  }//function post2FB end

//post test & image & video 2 pixnet
function post2pixnet(){

   //debug
  if(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');

  //debug
  if(window.debug) console.log(btn_post);

  //當按下 post 時
  btn_post[0].addEventListener('click',function(event){

    //debug
    if(window.debug) console.log('preventDefault & stopPropagation');

    //disable default event action
    event.preventDefault();

    //disbale event propagation
    event.stopPropagation();

    //debug
    if(window.debug) console.log('clicked');

    //取得要發布的內文區段
    post_conetent_section=document.getElementsByClassName('write_post _tl_write_post');

    //debug
    if(window.debug) console.log(post_conetent_section);

    //取得發布的網頁文字內容
    post_conetent_html=post_conetent_section[0].children[1].children[0].innerHTML;

    //debug
    if(window.debug) console.log(post_conetent_html);

    //debug
    if(window.debug) console.log(localStorage.qbpwcf);

    //debug
    if(window.debug) console.log(JSON.parse(localStorage.qbpwcf));

    //從 storage 取出 qbpwcf
    qbpwcf=JSON.parse(localStorage.qbpwcf);

    //儲存發布的網頁文字內容
    qbpwcf.Extention.LineTimeline.html=post_conetent_html;

    //debug
    if(window.debug) console.log(qbpwcf.Extention.LineTimeline.html);

    //將 qbpwcf 儲存到 storage
    localStorage.qbpwcf=JSON.stringify(qbpwcf);

    //debug
    if(window.debug) console.log(localStorage.qbpwcf);

     //debug
    if(window.debug) console.log(JSON.parse(localStorage.qbpwcf));

    //取得發布的文字內容
    post_conetent_text=post_conetent_section[0].children[1].children[0].innerText;

    //debug
    if(window.debug) console.log(post_conetent_text);

    //debug
    if(window.debug) console.log(JSON.parse(localStorage.qbpwcf));

    //從 storage 取出 qbpwcf
    qbpwcf=JSON.parse(localStorage.qbpwcf);

    //儲存發布的文字內容
    qbpwcf.Extention.LineTimeline.text=post_conetent_text;

    //debug
    if(window.debug) console.log(qbpwcf.Extention.LineTimeline.text);

    //將 qbpwcf 儲存到 storage
    localStorage.qbpwcf=JSON.stringify(qbpwcf);

    //debug
    if(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;

      //debug
      if(window.debug) console.log(post_content_image_section);

      //取得圖片的區域有多少張照片
      post_content_image_section_length=post_content_image_section.length

      //debug
      if(window.debug) console.log(post_content_image_section_length);

      //依照每張照片
      for(i=0;i<post_content_image_section_length;i++){

        //debug
        if(window.debug) console.log(post_content_image_section[i]);

        //debug
        if(window.debug) console.log(post_content_image_section[i].children[0].style.backgroundImage);

        //debug
        if(window.debug) console.log(post_content_image_section[i].children[0].style.backgroundImage.split('url(\"'));

        //debug
        if(window.debug) console.log(post_content_image_section[i].children[0].style.backgroundImage.split('url(\"')[1].split('\")'));

        //debug
        if(window.debug) console.log(post_content_image_section[i].children[0].style.backgroundImage.split('url(\"')[1].split('\")')[0]);

        //從 storage 取出 qbpwcf
        qbpwcf=JSON.parse(localStorage.qbpwcf);

        //儲存照片
        qbpwcf.Extention.LineTimeline.img.push(post_content_image_section[i].children[0].style.backgroundImage.split('url(\"')[1].split('\")')[0]);

        //debug
        if(window.debug) console.log(qbpwcf.Extention.LineTimeline.img);

        //將 qbpwcf 儲存到 storage
        localStorage.qbpwcf=JSON.stringify(qbpwcf);

        //debug
        if(window.debug) console.log(localStorage.qbpwcf);

        }//for end

      }//if end

    //post to youtube
    post2youtube();

    //post to fb
    post2FB();

    //post to pixnet
    post2pixnet();
  
    //init local storage
    initLocalStorage();

    });//addEventListen end

  }//function post_evevt end

//function show share button event
function showShareBtnEvent(){

  //debug
  if(window.debug) console.log('enter function showShareBtnEvent');

  //取得文章列表
  articles=document.querySelectorAll('article');

  //debug
  if(window.debug) console.log(articles);

  //set start point
  i=0;

  //針對每個文章
  while(i<articles.length){

    //debug
    if(window.debug) console.log(i);

    //取得index數值的內容
    index=Object.assign({},{i});

    //debug
    if(window.debug) console.log(index);

    //debug
    if(window.debug) console.log(index.i.valueOf());

    //取得index的數值
    index=index.i.valueOf();

     //debug
    if(window.debug) console.log(index);

    //debug
    if(window.debug) console.log(articles);

    //debug
    if(window.debug) console.log(articles[index]);

    //從 storage 取出 qbpwcf
    qbpwcf=JSON.parse(localStorage.qbpwcf);

    //儲存for的index
    qbpwcf.Extention.LineTimeline.forIndex=index;

    //debug
    if(window.debug) console.log(qbpwcf.Extention.LineTimeline.forIndex);

    //將 qbpwcf 儲存到 storage
    localStorage.qbpwcf=JSON.stringify(qbpwcf);

    //debug
    if(window.debug) console.log(localStorage.qbpwcf);

    //增加滑鼠移動進取後要出現後觸發事件
    articles[index].addEventListener('mouseover',function(event){

      //debug
      if(window.debug) console.log('enter mouseover event');

      //debug
      if(window.debug) console.log(event);

      //get event trigger element
      elementTrigger=event.target;

      //如果不是 article tag
      while(elementTrigger.nodeName!=='ARTICLE'){

        //取得上層元素
        elementTrigger=elementTrigger.parentElement;

        }//while end

      //從 storage 取出 qbpwcf
      qbpwcf=JSON.parse(localStorage.qbpwcf);

      //debug
      if(window.debug) console.log(qbpwcf);

      //儲存for的index
      i=qbpwcf.Extention.LineTimeline.forIndex;

      //debug
      if(window.debug) console.log(i);

      //取得index數值的內容
      index=Object.assign({},i);

      //debug
      if(window.debug) console.log(index);

      //create notify text node
      text=document.createTextNode('Click me to Post to FB & Youtube & Pixnet~ ');

      //create notify span
      notify_span=document.createElement('span');
      
      //put notify to span
      notify_span.appendChild(text);
      
      //create notify a
      notify_a=document.createElement('a');
      
      //create notify href
      notify_a.href="#";
      
      //prevent click event
      notify_a.onclick=function(e){
      
        e.preventDefault();
        
        //get content
        
        //debug
        if(window.debug) console.log('get post content');
        
        //save to localStorage
        
        //debug
        if(window.debug) console.log('save to localStorage');
        
        //scroll to top
        
        //debug
        if(window.debug) console.log('scroll to top');
        
        //click write new post
        
        //debug
        if(window.debug) console.log('click write new post');
        
        }
      
      //put notify_span to notify_a
      notify_a.appendChild(notify_span);
      
      //create ad text node
      text=document.createTextNode('Powered by QBPWCF!');

      //create ad span
      ad_span=document.createElement('span');

      //red color font
      ad_span.style.color='red';

      //put ad to span
      ad_span.appendChild(text);

      //create div node
      div=document.createElement('div');

      //將 span 內容放進 div 裡面
      div.appendChild(notify_a);
      div.appendChild(ad_span);
      
      //背景顏色
      div.style.backgroundColor='#CCCCFF';

      //debug
      if(window.debug) console.log(div);

      //debug
      if(window.debug) console.log(document);

                        //debug
                        if(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){

        //debug
        if(window.debug) console.log('no tool text');

        //將提示內容放到標題上方
        elementTrigger.prepend(div);

        //debug
        if(window.debug) console.log(elementTrigger.firstChild);

        }//if end

      });//articles event end

    //step +1
    i++;

    }//while end

  }//function showShareBtnEvent end

//function share button clcik event
function shareBtnClickEvent(){

        //get text

        //get img

        //get video

  }//function shareBtnClickEvent end

//init local storage
function initLocalStorage(){

  //json struc
  qbpwcf={

    Extention:{

      LineTimeline:{

          //text
          text:"",

          //html
          html:"",

          //img
          img:[],

          //video
          video:[]

          }
      }
  }

  //initil storage
  localStorage.qbpwcf=JSON.stringify(qbpwcf);

  }//function initLocationStorage end

//debug
console.log('found target url');

//on ready
setTimeout(function(){

  window.addEventListener('load', function(event){

    //debug
    console.log('All resources finished loading!');

    if(checkStorageSupport()===true){

      //init local storage
      initLocalStorage();

      //bind post event
      post_event();

      //show share button event
      showShareBtnEvent();

                  //bind click for share event
                  shareBtnClickEvent();

      }//if end

    });

  },1);