Auto redirect

手機版、電腦版網頁自動跳轉

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

// ==UserScript==
// @name             Auto redirect
// @description      手機版、電腦版網頁自動跳轉
// @namespace        7ED70DC0-CD34-11E7-8C84-6590899BC43F
// @match            https://m.gamer.com.tw/*
// @match            https://m.facebook.com/*
// @match            https://m.591.com.tw/v2/rent/*
// @match            https://m.cosdna.com/*
// @match            https://m.momoshop.com.tw/*
// @version          1.3.0
// @grant            none
// ==/UserScript==


function toPC () {
  switch (location.hostname) {
    // 巴哈
    case 'm.gamer.com.tw':
      document.querySelector('.gtm-nav-backpc').click()
      break
      
    // FB
    case 'm.facebook.com':
      if (location.pathname === '/story.php') {
        location.href = 'https://www.facebook.com/' + location.search.match(/[?&]id=([^&]+)/)[1] + '/posts/' + location.search.match(/[?&]story_fbid=([^&]+)/)[1]
      } else {
        location.href = 'https://www' + location.href.slice(9)
      }
      break
      
    // 591
    case 'm.591.com.tw':
      location.href = 'https://rent.591.com.tw/rent-detail-' + location.pathname.split('/').pop().match(/\d+/)[0] + '.html'
      break
  
    // CosDNA
    case 'm.cosdna.com':
      location.host = 'cosdna.com'
      break
  
    // momo
    case 'm.momoshop.com.tw':
      switch (location.pathname) {
        case '/goods.momo':
          // https://m.momoshop.com.tw/goods.momo?i_code=7502072
          location.href = 'https://www.momoshop.com.tw/goods/GoodsDetail.jsp' + location.search
          break
          
        case '/search.momo':
        // https://m.momoshop.com.tw/search.momo?searchKeyword=防噪音耳塞&couponSeq=&cpName=&searchType=1&cateCode=-1&ent=k&_imgSH=fourCardStyle
        // 不能直接使用全部 location.search,會搜尋不到任何東西
        let searchKeyword = location.search.match(/[?&]searchKeyword=([^?&]+)/)[1]
        location.href = 'https://www.momoshop.com.tw/search/searchShop.jsp?keyword=' + searchKeyword
        break
      }
      break
  }
}

function toMobile () {

}

if (navigator.userAgentData.mobile) {
  toMobile()
} else {
  toPC()
}