// 域名
const baseUrlPrefix = 'https://www.hkcd.com.hk/'

// 重定向至http
// changeHttp()

// 接入百度统计
var _hmt = _hmt || []
;(function() {
  var hm = document.createElement('script')
  hm.src = 'https://hm.baidu.com/hm.js?1dd4e7f5d7c025e6e59521cc54b3d5f2'
  var s = document.getElementsByTagName('script')[0]
  s.parentNode.insertBefore(hm, s)
})()

// 移动端跳往手机版
try {
  const urlhash = window.location.hash
  if(!urlhash.match('fromapp')) {
    if((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i))) {
      var link = window.location.href;
	  if(link.includes('hkcdweb/content_p')){
		  link = link.replace('hkcdweb/content_p', 'hkcdweb/content_p_app')
	  }else{
		link = link.replace('hkcdweb/content', 'content_app')
      for (let i = 2016; i < 2025; i++) {
        link = link.replace(`${i}/`, `${i}-`)
      }
	  }

      console.log(link)
      window.location.href = link;
    }
  }
} catch(err) {}

function changeHttp() {
  var targetProtocol = 'http:'
  if (window.location.protocol !== targetProtocol) {
    window.location.href = targetProtocol + window.location.href.substring(window.location.protocol.length)
  }
}