Skip to content

Instantly share code, notes, and snippets.

@naoyeye
Last active October 31, 2018 06:27
Show Gist options
  • Save naoyeye/1d7deff67f0782f6ea00e0eda82b93d2 to your computer and use it in GitHub Desktop.
Save naoyeye/1d7deff67f0782f6ea00e0eda82b93d2 to your computer and use it in GitHub Desktop.
虾米的mac 客户端,歌曲页面复制链接分享时,拿到的是h5页面的链接,h5页面没有针对 pc做适配,这个脚本可以在打开虾米歌曲h5页面时,自动跳转到正常的虾米歌曲 pc 端页面。
// ==UserScript==
// @name h5XiamiAutoRedirect
// @namespace h5-xiami-auto-redirect
// @version 0.1
// @description try to take over the world!
// @author naoyeye
// @homepage http://han.im
// @include https://h.xiami.com/song.html?id=*
// @include https://h.xiami.com/collect_detail.html?id=*
// @include https://h.xiami.com/artist_detail.html?id=*
// @include https://h.xiami.com/album_detail.html?id=*
// @grant none
// ==/UserScript==
(() => {
'use strict';
/*
脚本介绍:
支持[歌曲、歌单、歌手、专辑]四类虾米 h5 url 自动跳转到对应 web 页面
应用场景:
点击虾米 mac 客户端的分享按钮后,虾米客户端会自动复制 h5 url到系统剪贴板,这时候如果在电脑浏览器里粘贴 url 打开,会发现是一个没做过适配的 h5 页面,体验很差。
用了此脚本后,打开这类的h5页面会自动跳转到 web 页面
h5 url 例子:
'https://h.xiami.com/song.html?id=59457&_uxid=9CC3A5065844F05107D72E711A083CBA',
'https://h.xiami.com/collect_detail.html?id=431536215&_uxid=9CC3A5065844F05107D72E711A083CBA',
'https://h.xiami.com/artist_detail.html?id=978&_uxid=9CC3A5065844F05107D72E711A083CBA',
'https://h.xiami.com/album_detail.html?id=4907&_uxid=9CC3A5065844F05107D72E711A083CBA'
*/
const href = window.location.href
const regex = /https:\/\/h.xiami.com\/(song|collect_detail|artist_detail|album_detail).html\?id=(\d+)&_uxid=[a-zA-Z0-9]+/g
let result = regex.exec(href)
let targetType = result[1].split('_')[0]
let targetId = result[2]
window.location.href = `https://www.xiami.com/${targetType}/${targetId}`
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment