Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(shortcut): 增加浏览器内全局快捷键的功能 #146

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Listen 1 (Chrome Extension) V1.6.0
Listen 1 (Chrome Extension) V1.6.1
==========
最后更新于2018年04月23日
最后更新于2018年05月30日

[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE)

Expand Down Expand Up @@ -45,6 +45,9 @@ Firefox打包安装
更新日志
-------

`2018-05-30`
* 修复QQ音乐无法播放的问题(感谢@noschoollee 提供修复方案)

`2018-04-23`
* 修复虾米音乐无法播放的问题

Expand Down
26 changes: 25 additions & 1 deletion js/background.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
let listen1Tab = undefined;

chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.create({'url': chrome.extension.getURL('listen1.html')}, function(tab) {
// Tab opened.
listen1Tab = tab
});
});

Expand Down Expand Up @@ -71,4 +74,25 @@ chrome.runtime.onMessage.addListener(
Github.handleCallback(code);
sendResponse();
}
);
);

chrome.commands.onCommand.addListener(function (command) {
const [viewWindow] = chrome.extension.getViews({
type: 'tab',
tabId: listen1Tab.id
});

switch (command) {
case 'play_next':
viewWindow.document.querySelector('.next').click();
break;
case 'play_prev':
viewWindow.document.querySelector('.previous').click();
break;
case 'play_pause':
viewWindow.document.querySelector('.mastfoot a.play').click();
break;
default:
console.log('不支持的快捷键')
}
});
21 changes: 13 additions & 8 deletions js/provider/qq.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,13 @@ var qq = (function() {
}

var qq_bootstrap_track = function(sound, track, success, failure, hm, se) {
var target_url ='http://base.music.qq.com/fcgi-bin/fcg_musicexpress.fcg?' +
'json=3&guid=780782017&g_tk=938407465&loginUin=0&hostUin=0&' +
'format=jsonp&inCharset=GB2312&outCharset=GB2312&notice=0&' +
'platform=yqq&jsonpCallback=jsonCallback&needNewCode=0';
var target_url ='https://c.y.qq.com/base/fcgi-bin/fcg_music_express_mobile3.fcg' +
'?g_tk=195219765&jsonpCallback=MusicJsonCallback004680169373158849' +
'&loginUin=1297716249&hostUin=0&format=json&inCharset=utf8' +
'&outCharset=utf-8&notice=0&platform=yqq&needNewCode=0' +
'&cid=205361747&callback=MusicJsonCallback004680169373158849' +
'&uin=1297716249&songmid='+ track.id.slice('qqtrack_'.length) +
'&filename=C400'+ track.id.slice('qqtrack_'.length) + '.m4a&guid=7332953645';

hm({
url:target_url,
Expand All @@ -249,11 +252,13 @@ var qq = (function() {
})
.then(function(response) {
var data = response.data;
data = data.slice('jsonCallback('.length, -');'.length);
data = data.slice(data.indexOf('(')+1,data.length-1);
data = JSON.parse(data);
var token = data.key;
var url = 'http://dl.stream.qqmusic.qq.com/C200' + track.id.slice('qqtrack_'.length) + '.m4a?vkey=' +
token + '&fromtag=0&guid=780782017';
var token = data.data.items[0].vkey;
var url = 'http://dl.stream.qqmusic.qq.com/C400' +
track.id.slice('qqtrack_'.length) +
'.m4a?vkey=' + token +
'&uin=1297716249&fromtag=0&guid=7332953645';
sound.url = url;
success();
});
Expand Down
2 changes: 1 addition & 1 deletion listen1.html
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ <h3 class="masthead-brand" ng-click="showTag(2)">Listen 1</h3>
<div class="settings-content">
<p> Listen 1 主页: <a href="http://listen1.github.io/listen1/" target="_blank"> http://listen1.github.io/listen1/ </a> </p>
<p> Listen 1 邮箱: githublisten1@gmail.com </p>
<p> 当前版本 1.6.0 (本软件基于MIT协议开源免费)</p>
<p> 当前版本 1.6.1 (本软件基于MIT协议开源免费)</p>
</div>
</div>
</div>
Expand Down
30 changes: 28 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,36 @@
"manifest_version": 2,
"name": "Listen 1",
"permissions": [ "notifications", "unlimitedStorage", "downloads", "storage", "contextMenus", "tabs", "*://music.163.com/*", "*://*.xiami.com/*", "*://*.qq.com/*", "*://api.github.com/*", "*://github.com/*", "webRequest", "webRequestBlocking"],
"version": "1.6.0",
"version": "1.6.1",
"web_accessible_resources": [ "images/*" ],
"content_scripts": [{
"matches": ["https://listen1.github.io/listen1/*"],
"js": ["js/oauth_callback.js"]
}]
}],
"commands": {
"play_next": {
"suggested_key": {
"default": "Ctrl+Shift+Right",
"mac": "Command+Shift+Right"
},
"description": "Play next song.",
"global": true
},
"play_prev": {
"suggested_key": {
"default": "Ctrl+Shift+Left",
"mac": "Command+Shift+Left"
},
"description": "Play previous song.",
"global": true
},
"play_pause": {
"suggested_key": {
"default": "Ctrl+Shift+Up",
"mac": "Command+Shift+Up"
},
"description": "Toggle play pause state.",
"global": true
}
}
}
30 changes: 28 additions & 2 deletions manifest_firefox.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,36 @@
"manifest_version": 2,
"name": "Listen 1",
"permissions": [ "notifications", "unlimitedStorage", "downloads", "storage", "contextMenus", "tabs", "*://music.163.com/*", "*://*.xiami.com/*", "*://*.qq.com/*", "*://api.github.com/*", "*://github.com/*", "webRequest", "webRequestBlocking"],
"version": "1.6.0",
"version": "1.6.1",
"web_accessible_resources": [ "images/*" ],
"content_scripts": [{
"matches": ["https://listen1.github.io/listen1/*"],
"js": ["js/oauth_callback.js"]
}]
}],
"commands": {
"play_next": {
"suggested_key": {
"default": "Ctrl+Shift+Right",
"mac": "Command+Shift+Right"
},
"description": "Play next song.",
"global": true
},
"play_prev": {
"suggested_key": {
"default": "Ctrl+Shift+Left",
"mac": "Command+Shift+Left"
},
"description": "Play previous song.",
"global": true
},
"play_pause": {
"suggested_key": {
"default": "Ctrl+Shift+Up",
"mac": "Command+Shift+Up"
},
"description": "Toggle play pause state.",
"global": true
}
}
}