Auto redirect

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==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()
}