1
mirror of https://github.com/nilaoda/N_m3u8DL-CLI synced 2025-09-05 23:29:33 +02:00

Compare commits

...

28 Commits
1.3.1 ... 2.0.2

Author SHA1 Message Date
nilaoda
c2953a3d43 修复腾讯视频m3u8获取代码 2019-07-10 21:31:41 +08:00
nilaoda
6f2ebfba2d 增加气球云教程 2019-07-10 00:49:39 +08:00
nilaoda
3c1b893919 Update README.md 2019-07-09 01:54:59 +08:00
nilaoda
8b6f411af9 add doc 2019-07-09 01:54:12 +08:00
nilaoda
6cfd74f3a0 add docs 2019-07-09 01:42:37 +08:00
nilaoda
044068016b Update README.md 2019-07-07 22:35:53 +08:00
nilaoda
6d21ef0a10 Update README.md 2019-07-07 21:36:36 +08:00
nilaoda
6d1834ca9f Update README.md 2019-07-07 21:28:37 +08:00
nilaoda
3e215359b4 Javascript 2019-07-07 21:26:57 +08:00
nilaoda
3d9610d3bb 搜狐 2019-07-07 16:41:17 +08:00
nilaoda
377c575c72 Update README.md 2019-06-21 21:41:12 +08:00
nilaoda
c02d737125 Update README.md 2019-06-21 21:26:04 +08:00
nilaoda
c1fb395ee0 爱奇艺代码 2019-06-19 20:53:54 +08:00
nilaoda
3920ae6178 Update README.md 2019-06-19 20:34:42 +08:00
nilaoda
f96ea497b7 Update README.md 2019-06-16 16:24:29 +08:00
nilaoda
0013ec4bb5 Update README.md 2019-06-16 16:05:26 +08:00
nilaoda
604c25a2be Update README.md 2019-06-16 16:05:15 +08:00
nilaoda
a83afd8908 Update README.md 2019-06-16 15:46:33 +08:00
nilaoda
206342c4cf Update README.md 2019-06-14 11:29:26 +08:00
nilaoda
296739910e Update README.md 2019-06-14 11:29:02 +08:00
nilaoda
5a62342145 add mgtv 2019-06-13 17:28:59 +08:00
nilaoda
64df11fefb 更新优酷代码 2019-06-13 17:05:50 +08:00
nilaoda
5d82bc9135 Update README.md 2019-06-12 11:04:41 +08:00
nilaoda
2a61b61205 Update README.md 2019-06-11 12:54:37 +08:00
nilaoda
15568f917c Update README.md 2019-06-11 12:52:05 +08:00
nilaoda
b196990972 Update README.md 2019-06-11 11:23:19 +08:00
nilaoda
d4a94d185a Update README.md 2019-06-08 23:04:43 +08:00
nilaoda
d865c05d9a Update README.md 2019-06-08 01:14:18 +08:00
51 changed files with 6451 additions and 35 deletions

View File

@@ -1,36 +1,14 @@
```
███╗ ██╗ ███╗ ███╗██████╗ ██╗ ██╗ █████╗ ██████╗ ██╗ ██████╗██╗ ██╗
████╗ ██║ ████╗ ████║╚════██╗██║ ██║██╔══██╗██╔══██╗██║ ██╔════╝██║ ██║
██╔██╗ ██║ ██╔████╔██║ █████╔╝██║ ██║╚█████╔╝██║ ██║██║█████╗██║ ██║ ██║
██║╚██╗██║ ██║╚██╔╝██║ ╚═══██╗██║ ██║██╔══██╗██║ ██║██║╚════╝██║ ██║ ██║
██║ ╚████║███████╗██║ ╚═╝ ██║██████╔╝╚██████╔╝╚█████╔╝██████╔╝███████╗ ╚██████╗███████╗██║
╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝╚═════╝ ╚═════╝ ╚════╝ ╚═════╝ ╚══════╝ ╚═════╝╚══════╝╚═╝
```
# N_m3u8DL-CLI
一个m3u8下载器
## 基本用法
双击exe然后输入m3u8链接或拖入m3u8文件或拖入本程序生成的json文件按下回车键。
## 高级用法
使用命令行参数
```
N_m3u8DL-CLI.exe <URL|JSON> [OPTIONS]
--workDir Directory 设定程序工作目录
--saveName Filename 设定存储文件名(不包括后缀)
--baseUrl BaseUrl 设定Baseurl
--headers headers 设定请求头,格式 key:value 使用|分割不同的key&value
--maxThreads Thread 设定程序的最大线程数(默认为32)
--minThreads Thread 设定程序的最小线程数(默认为16)
--retryCount Count 设定程序的重试次数(默认为15)
--muxSetJson File 使用外部json文件定义混流选项
--enableDelAfterDone 开启下载后删除临时文件夹的功能
--enableMuxFastStart 开启混流mp4的FastStart特性
--enableBinaryMerge 开启二进制合并分片
--enableParseOnly 开启仅解析模式(程序只进行到meta.json)
```
附录一个典型的混流Json文件应该长这个样子
```
{
"muxFormat": "mp4",
"fastStart": "True",
"poster": "文件路径,\需写为\\",
"audioName": "",
"title": "",
"copyright": "",
"comment": ""
}
```
一个m3u8下载器下载地址https://github.com/nilaoda/N_m3u8DL-CLI/releases
# 用户文档
https://nilaoda.github.io/N_m3u8DL-CLI/

583
docs/Advanced.html Normal file

File diff suppressed because it is too large Load Diff

483
docs/GetM3u8.html Normal file

File diff suppressed because it is too large Load Diff

466
docs/Introductory.html Normal file

File diff suppressed because it is too large Load Diff

475
docs/LinetvParser.html Normal file

File diff suppressed because it is too large Load Diff

469
docs/M3U8URL2File.html Normal file

File diff suppressed because it is too large Load Diff

481
docs/SimpleGUI.html Normal file

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 382 KiB

Binary file not shown.

View File

@@ -0,0 +1,120 @@
.gitbook-donate {
padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;
}
#rewardButton {
cursor: pointer;
border: 0;
outline: 0;
border-radius: 100%;
padding: 0;
margin: 0;
letter-spacing: normal;
text-transform: none;
text-indent: 0px;
text-shadow: none;
}
#rewardButton span {
display: inline-block;
width: 80px;
height: 35px;
line-height: 35px;
border-radius: 5px;
color: #fff;
font-weight: 400;
font-style: normal;
font-variant: normal;
font-stretch: normal;
font-size: 18px;
font-family: "Microsoft Yahei";
background: #f44336;
}
#rewardButton span:hover {
background: #f7877f;
}
#QR {
padding-top: 20px;
}
#QR a {
border: 0;
}
#QR img {
width: 180px;
max-width: 100%;
display: inline-block;
margin: 0.8em 2em 0 2em;
}
#wechat:hover p {
animation: roll 0.1s infinite linear;
-webkit-animation: roll 0.1s infinite linear;
-moz-animation: roll 0.1s infinite linear;
}
#alipay:hover p {
animation: roll 0.1s infinite linear;
-webkit-animation: roll 0.1s infinite linear;
-moz-animation: roll 0.1s infinite linear;
}
@-moz-keyframes roll {
from {
-webkit-transform: rotateZ(30deg);
-moz-transform: rotateZ(30deg);
-ms-transform: rotateZ(30deg);
-o-transform: rotateZ(30deg);
transform: rotateZ(30deg);
}
to {
-webkit-transform: rotateZ(-30deg);
-moz-transform: rotateZ(-30deg);
-ms-transform: rotateZ(-30deg);
-o-transform: rotateZ(-30deg);
transform: rotateZ(-30deg);
}
}
@-webkit-keyframes roll {
from {
-webkit-transform: rotateZ(30deg);
-moz-transform: rotateZ(30deg);
-ms-transform: rotateZ(30deg);
-o-transform: rotateZ(30deg);
transform: rotateZ(30deg);
}
to {
-webkit-transform: rotateZ(-30deg);
-moz-transform: rotateZ(-30deg);
-ms-transform: rotateZ(-30deg);
-o-transform: rotateZ(-30deg);
transform: rotateZ(-30deg);
}
}
@-o-keyframes roll {
from {
-webkit-transform: rotateZ(30deg);
-moz-transform: rotateZ(30deg);
-ms-transform: rotateZ(30deg);
-o-transform: rotateZ(30deg);
transform: rotateZ(30deg);
}
to {
-webkit-transform: rotateZ(-30deg);
-moz-transform: rotateZ(-30deg);
-ms-transform: rotateZ(-30deg);
-o-transform: rotateZ(-30deg);
transform: rotateZ(-30deg);
}
}
@keyframes roll {
from {
-webkit-transform: rotateZ(30deg);
-moz-transform: rotateZ(30deg);
-ms-transform: rotateZ(30deg);
-o-transform: rotateZ(30deg);
transform: rotateZ(30deg);
}
to {
-webkit-transform: rotateZ(-30deg);
-moz-transform: rotateZ(-30deg);
-ms-transform: rotateZ(-30deg);
-o-transform: rotateZ(-30deg);
transform: rotateZ(-30deg);
}
}

View File

@@ -0,0 +1,56 @@
require(['gitbook', 'jQuery'], function(gitbook, $) {
var wechatURL;
var alipayURL;
var titleText;
var buttonText;
var wechatText;
var alipayText;
function insertDonateLink() {
if ($('.gitbook-donate').length === 0 && wechatURL !== undefined && (wechatURL !== '' || alipayURL !== '')) {
var html = [
'<div class="gitbook-donate">',
'<div>' + titleText + '</div>',
'<button id="rewardButton" disable="enable" onclick="var qr = document.getElementById(\'QR\'); if (qr.style.display === \'none\') {qr.style.display=\'block\';} else {qr.style.display=\'none\'}">',
'<span>' + buttonText + '</span>',
'</button>',
'<div id="QR" style="display: none;">'
];
if (wechatURL !== '') {
html = html.concat([
'<div id="wechat" style="display: inline-block">',
'<a href="' + wechatURL + '" class="fancybox" rel="group">',
'<img id="wechat_qr" src="' + wechatURL + '" alt="WeChat Pay"/>',
'</a>',
'<p>' + wechatText + '</p>',
'</div>'
]);
}
if (alipayURL !== '') {
html = html.concat([
'<div id="alipay" style="display: inline-block">',
'<a href="' + alipayURL+ '" class="fancybox" rel="group">',
'<img id="alipay_qr" src="' + alipayURL + '" alt="Alipay"/>',
'</a>',
'<p>' + alipayText + '</p>', '</div>'
]);
}
html = html.concat(['</div>', '</div>']);
$('.page-inner section.normal:last').after(html.join(''));
}
}
gitbook.events.bind('start', function(e, config) {
wechatURL = config.donate.wechat || '';
wechatText = config.donate.wechatText || '微信捐赠';
alipayURL = config.donate.alipay || '';
alipayText = config.donate.alipayText || '支付宝捐赠';
titleText = config.donate.title || '';
buttonText = config.donate.button || '赏';
insertDonateLink();
});
gitbook.events.bind('page.change', function() {
insertDonateLink();
});
});

View File

@@ -0,0 +1,240 @@
require(['gitbook', 'jquery'], function(gitbook, $) {
// Configuration
var MAX_SIZE = 4,
MIN_SIZE = 0,
BUTTON_ID;
// Current fontsettings state
var fontState;
// Default themes
var THEMES = [
{
config: 'white',
text: 'White',
id: 0
},
{
config: 'sepia',
text: 'Sepia',
id: 1
},
{
config: 'night',
text: 'Night',
id: 2
}
];
// Default font families
var FAMILIES = [
{
config: 'serif',
text: 'Serif',
id: 0
},
{
config: 'sans',
text: 'Sans',
id: 1
}
];
// Return configured themes
function getThemes() {
return THEMES;
}
// Modify configured themes
function setThemes(themes) {
THEMES = themes;
updateButtons();
}
// Return configured font families
function getFamilies() {
return FAMILIES;
}
// Modify configured font families
function setFamilies(families) {
FAMILIES = families;
updateButtons();
}
// Save current font settings
function saveFontSettings() {
gitbook.storage.set('fontState', fontState);
update();
}
// Increase font size
function enlargeFontSize(e) {
e.preventDefault();
if (fontState.size >= MAX_SIZE) return;
fontState.size++;
saveFontSettings();
}
// Decrease font size
function reduceFontSize(e) {
e.preventDefault();
if (fontState.size <= MIN_SIZE) return;
fontState.size--;
saveFontSettings();
}
// Change font family
function changeFontFamily(configName, e) {
if (e && e instanceof Event) {
e.preventDefault();
}
var familyId = getFontFamilyId(configName);
fontState.family = familyId;
saveFontSettings();
}
// Change type of color theme
function changeColorTheme(configName, e) {
if (e && e instanceof Event) {
e.preventDefault();
}
var $book = gitbook.state.$book;
// Remove currently applied color theme
if (fontState.theme !== 0)
$book.removeClass('color-theme-'+fontState.theme);
// Set new color theme
var themeId = getThemeId(configName);
fontState.theme = themeId;
if (fontState.theme !== 0)
$book.addClass('color-theme-'+fontState.theme);
saveFontSettings();
}
// Return the correct id for a font-family config key
// Default to first font-family
function getFontFamilyId(configName) {
// Search for plugin configured font family
var configFamily = $.grep(FAMILIES, function(family) {
return family.config == configName;
})[0];
// Fallback to default font family
return (!!configFamily)? configFamily.id : 0;
}
// Return the correct id for a theme config key
// Default to first theme
function getThemeId(configName) {
// Search for plugin configured theme
var configTheme = $.grep(THEMES, function(theme) {
return theme.config == configName;
})[0];
// Fallback to default theme
return (!!configTheme)? configTheme.id : 0;
}
function update() {
var $book = gitbook.state.$book;
$('.font-settings .font-family-list li').removeClass('active');
$('.font-settings .font-family-list li:nth-child('+(fontState.family+1)+')').addClass('active');
$book[0].className = $book[0].className.replace(/\bfont-\S+/g, '');
$book.addClass('font-size-'+fontState.size);
$book.addClass('font-family-'+fontState.family);
if(fontState.theme !== 0) {
$book[0].className = $book[0].className.replace(/\bcolor-theme-\S+/g, '');
$book.addClass('color-theme-'+fontState.theme);
}
}
function init(config) {
// Search for plugin configured font family
var configFamily = getFontFamilyId(config.family),
configTheme = getThemeId(config.theme);
// Instantiate font state object
fontState = gitbook.storage.get('fontState', {
size: config.size || 2,
family: configFamily,
theme: configTheme
});
update();
}
function updateButtons() {
// Remove existing fontsettings buttons
if (!!BUTTON_ID) {
gitbook.toolbar.removeButton(BUTTON_ID);
}
// Create buttons in toolbar
BUTTON_ID = gitbook.toolbar.createButton({
icon: 'fa fa-font',
label: 'Font Settings',
className: 'font-settings',
dropdown: [
[
{
text: 'A',
className: 'font-reduce',
onClick: reduceFontSize
},
{
text: 'A',
className: 'font-enlarge',
onClick: enlargeFontSize
}
],
$.map(FAMILIES, function(family) {
family.onClick = function(e) {
return changeFontFamily(family.config, e);
};
return family;
}),
$.map(THEMES, function(theme) {
theme.onClick = function(e) {
return changeColorTheme(theme.config, e);
};
return theme;
})
]
});
}
// Init configuration at start
gitbook.events.bind('start', function(e, config) {
var opts = config.fontsettings;
// Generate buttons at start
updateButtons();
// Init current settings
init(opts);
});
// Expose API
gitbook.fontsettings = {
enlargeFontSize: enlargeFontSize,
reduceFontSize: reduceFontSize,
setTheme: changeColorTheme,
setFamily: changeFontFamily,
getThemes: getThemes,
setThemes: setThemes,
getFamilies: getFamilies,
setFamilies: setFamilies
};
});

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,14 @@
require([ 'gitbook' ], function (gitbook) {
gitbook.events.bind('start', function (e, config) {
var githubURL = config.github.url;
gitbook.toolbar.createButton({
icon: 'fa fa-github',
label: 'GitHub',
position: 'right',
onClick: function() {
window.open(githubURL)
}
});
});
});

View File

@@ -0,0 +1,135 @@
pre,
code {
/* http://jmblog.github.io/color-themes-for-highlightjs */
/* Tomorrow Comment */
/* Tomorrow Red */
/* Tomorrow Orange */
/* Tomorrow Yellow */
/* Tomorrow Green */
/* Tomorrow Aqua */
/* Tomorrow Blue */
/* Tomorrow Purple */
}
pre .hljs-comment,
code .hljs-comment,
pre .hljs-title,
code .hljs-title {
color: #8e908c;
}
pre .hljs-variable,
code .hljs-variable,
pre .hljs-attribute,
code .hljs-attribute,
pre .hljs-tag,
code .hljs-tag,
pre .hljs-regexp,
code .hljs-regexp,
pre .hljs-deletion,
code .hljs-deletion,
pre .ruby .hljs-constant,
code .ruby .hljs-constant,
pre .xml .hljs-tag .hljs-title,
code .xml .hljs-tag .hljs-title,
pre .xml .hljs-pi,
code .xml .hljs-pi,
pre .xml .hljs-doctype,
code .xml .hljs-doctype,
pre .html .hljs-doctype,
code .html .hljs-doctype,
pre .css .hljs-id,
code .css .hljs-id,
pre .css .hljs-class,
code .css .hljs-class,
pre .css .hljs-pseudo,
code .css .hljs-pseudo {
color: #c82829;
}
pre .hljs-number,
code .hljs-number,
pre .hljs-preprocessor,
code .hljs-preprocessor,
pre .hljs-pragma,
code .hljs-pragma,
pre .hljs-built_in,
code .hljs-built_in,
pre .hljs-literal,
code .hljs-literal,
pre .hljs-params,
code .hljs-params,
pre .hljs-constant,
code .hljs-constant {
color: #f5871f;
}
pre .ruby .hljs-class .hljs-title,
code .ruby .hljs-class .hljs-title,
pre .css .hljs-rules .hljs-attribute,
code .css .hljs-rules .hljs-attribute {
color: #eab700;
}
pre .hljs-string,
code .hljs-string,
pre .hljs-value,
code .hljs-value,
pre .hljs-inheritance,
code .hljs-inheritance,
pre .hljs-header,
code .hljs-header,
pre .hljs-addition,
code .hljs-addition,
pre .ruby .hljs-symbol,
code .ruby .hljs-symbol,
pre .xml .hljs-cdata,
code .xml .hljs-cdata {
color: #718c00;
}
pre .css .hljs-hexcolor,
code .css .hljs-hexcolor {
color: #3e999f;
}
pre .hljs-function,
code .hljs-function,
pre .python .hljs-decorator,
code .python .hljs-decorator,
pre .python .hljs-title,
code .python .hljs-title,
pre .ruby .hljs-function .hljs-title,
code .ruby .hljs-function .hljs-title,
pre .ruby .hljs-title .hljs-keyword,
code .ruby .hljs-title .hljs-keyword,
pre .perl .hljs-sub,
code .perl .hljs-sub,
pre .javascript .hljs-title,
code .javascript .hljs-title,
pre .coffeescript .hljs-title,
code .coffeescript .hljs-title {
color: #4271ae;
}
pre .hljs-keyword,
code .hljs-keyword,
pre .javascript .hljs-function,
code .javascript .hljs-function {
color: #8959a8;
}
pre .hljs,
code .hljs {
display: block;
background: white;
color: #4d4d4c;
padding: 0.5em;
}
pre .coffeescript .javascript,
code .coffeescript .javascript,
pre .javascript .xml,
code .javascript .xml,
pre .tex .hljs-formula,
code .tex .hljs-formula,
pre .xml .javascript,
code .xml .javascript,
pre .xml .vbscript,
code .xml .vbscript,
pre .xml .css,
code .xml .css,
pre .xml .hljs-cdata,
code .xml .hljs-cdata {
opacity: 0.5;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,11 @@
(function() {
var newEl = document.createElement('script'),
firstScriptTag = document.getElementsByTagName('script')[0];
if (firstScriptTag) {
newEl.async = 1;
newEl.src = '//' + window.location.hostname + ':35729/livereload.js';
firstScriptTag.parentNode.insertBefore(newEl, firstScriptTag);
}
})();

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,59 @@
require([
'gitbook',
'jquery'
], function(gitbook, $) {
// Define global search engine
function LunrSearchEngine() {
this.index = null;
this.store = {};
this.name = 'LunrSearchEngine';
}
// Initialize lunr by fetching the search index
LunrSearchEngine.prototype.init = function() {
var that = this;
var d = $.Deferred();
$.getJSON(gitbook.state.basePath+'/search_index.json')
.then(function(data) {
// eslint-disable-next-line no-undef
that.index = lunr.Index.load(data.index);
that.store = data.store;
d.resolve();
});
return d.promise();
};
// Search for a term and return results
LunrSearchEngine.prototype.search = function(q, offset, length) {
var that = this;
var results = [];
if (this.index) {
results = $.map(this.index.search(q), function(result) {
var doc = that.store[result.ref];
return {
title: doc.title,
url: doc.url,
body: doc.summary || doc.body
};
});
}
return $.Deferred().resolve({
query: q,
results: results.slice(0, length),
count: results.length
}).promise();
};
// Set gitbook research
gitbook.events.bind('start', function(e, config) {
var engine = gitbook.search.getEngine();
if (!engine) {
gitbook.search.setEngine(LunrSearchEngine, config);
}
});
});

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,50 @@
require([
'gitbook',
'jquery'
], function(gitbook, $) {
// Global search objects
var engine = null;
var initialized = false;
// Set a new search engine
function setEngine(Engine, config) {
initialized = false;
engine = new Engine(config);
init(config);
}
// Initialize search engine with config
function init(config) {
if (!engine) throw new Error('No engine set for research. Set an engine using gitbook.research.setEngine(Engine).');
return engine.init(config)
.then(function() {
initialized = true;
gitbook.events.trigger('search.ready');
});
}
// Launch search for query q
function query(q, offset, length) {
if (!initialized) throw new Error('Search has not been initialized');
return engine.search(q, offset, length);
}
// Get stats about search
function getEngine() {
return engine? engine.name : null;
}
function isInitialized() {
return initialized;
}
// Initialize gitbook.search
gitbook.search = {
setEngine: setEngine,
getEngine: getEngine,
query: query,
isInitialized: isInitialized
};
});

View File

@@ -0,0 +1,35 @@
/*
This CSS only styled the search results section, not the search input
It defines the basic interraction to hide content when displaying results, etc
*/
#book-search-results .search-results {
display: none;
}
#book-search-results .search-results ul.search-results-list {
list-style-type: none;
padding-left: 0;
}
#book-search-results .search-results ul.search-results-list li {
margin-bottom: 1.5rem;
padding-bottom: 0.5rem;
/* Highlight results */
}
#book-search-results .search-results ul.search-results-list li p em {
background-color: rgba(255, 220, 0, 0.4);
font-style: normal;
}
#book-search-results .search-results .no-results {
display: none;
}
#book-search-results.open .search-results {
display: block;
}
#book-search-results.open .search-noresults {
display: none;
}
#book-search-results.no-results .search-results .has-results {
display: none;
}
#book-search-results.no-results .search-results .no-results {
display: block;
}

View File

@@ -0,0 +1,213 @@
require([
'gitbook',
'jquery'
], function(gitbook, $) {
var MAX_RESULTS = 15;
var MAX_DESCRIPTION_SIZE = 500;
var usePushState = (typeof history.pushState !== 'undefined');
// DOM Elements
var $body = $('body');
var $bookSearchResults;
var $searchInput;
var $searchList;
var $searchTitle;
var $searchResultsCount;
var $searchQuery;
// Throttle search
function throttle(fn, wait) {
var timeout;
return function() {
var ctx = this, args = arguments;
if (!timeout) {
timeout = setTimeout(function() {
timeout = null;
fn.apply(ctx, args);
}, wait);
}
};
}
function displayResults(res) {
$bookSearchResults.addClass('open');
var noResults = res.count == 0;
$bookSearchResults.toggleClass('no-results', noResults);
// Clear old results
$searchList.empty();
// Display title for research
$searchResultsCount.text(res.count);
$searchQuery.text(res.query);
// Create an <li> element for each result
res.results.forEach(function(res) {
var $li = $('<li>', {
'class': 'search-results-item'
});
var $title = $('<h3>');
var $link = $('<a>', {
'href': gitbook.state.basePath + '/' + res.url,
'text': res.title
});
var content = res.body.trim();
if (content.length > MAX_DESCRIPTION_SIZE) {
content = content.slice(0, MAX_DESCRIPTION_SIZE).trim()+'...';
}
var $content = $('<p>').html(content);
$link.appendTo($title);
$title.appendTo($li);
$content.appendTo($li);
$li.appendTo($searchList);
});
}
function launchSearch(q) {
// Add class for loading
$body.addClass('with-search');
$body.addClass('search-loading');
// Launch search query
throttle(gitbook.search.query(q, 0, MAX_RESULTS)
.then(function(results) {
displayResults(results);
})
.always(function() {
$body.removeClass('search-loading');
}), 1000);
}
function closeSearch() {
$body.removeClass('with-search');
$bookSearchResults.removeClass('open');
}
function launchSearchFromQueryString() {
var q = getParameterByName('q');
if (q && q.length > 0) {
// Update search input
$searchInput.val(q);
// Launch search
launchSearch(q);
}
}
function bindSearch() {
// Bind DOM
$searchInput = $('#book-search-input input');
$bookSearchResults = $('#book-search-results');
$searchList = $bookSearchResults.find('.search-results-list');
$searchTitle = $bookSearchResults.find('.search-results-title');
$searchResultsCount = $searchTitle.find('.search-results-count');
$searchQuery = $searchTitle.find('.search-query');
// Launch query based on input content
function handleUpdate() {
var q = $searchInput.val();
if (q.length == 0) {
closeSearch();
}
else {
launchSearch(q);
}
}
// Detect true content change in search input
// Workaround for IE < 9
var propertyChangeUnbound = false;
$searchInput.on('propertychange', function(e) {
if (e.originalEvent.propertyName == 'value') {
handleUpdate();
}
});
// HTML5 (IE9 & others)
$searchInput.on('input', function(e) {
// Unbind propertychange event for IE9+
if (!propertyChangeUnbound) {
$(this).unbind('propertychange');
propertyChangeUnbound = true;
}
handleUpdate();
});
// Push to history on blur
$searchInput.on('blur', function(e) {
// Update history state
if (usePushState) {
var uri = updateQueryString('q', $(this).val());
history.pushState({ path: uri }, null, uri);
}
});
}
gitbook.events.on('page.change', function() {
bindSearch();
closeSearch();
// Launch search based on query parameter
if (gitbook.search.isInitialized()) {
launchSearchFromQueryString();
}
});
gitbook.events.on('search.ready', function() {
bindSearch();
// Launch search from query param at start
launchSearchFromQueryString();
});
function getParameterByName(name) {
var url = window.location.href;
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)', 'i'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
function updateQueryString(key, value) {
value = encodeURIComponent(value);
var url = window.location.href;
var re = new RegExp('([?&])' + key + '=.*?(&|#|$)(.*)', 'gi'),
hash;
if (re.test(url)) {
if (typeof value !== 'undefined' && value !== null)
return url.replace(re, '$1' + key + '=' + value + '$2$3');
else {
hash = url.split('#');
url = hash[0].replace(re, '$1$3').replace(/(&|\?)$/, '');
if (typeof hash[1] !== 'undefined' && hash[1] !== null)
url += '#' + hash[1];
return url;
}
}
else {
if (typeof value !== 'undefined' && value !== null) {
var separator = url.indexOf('?') !== -1 ? '&' : '?';
hash = url.split('#');
url = hash[0] + separator + key + '=' + value;
if (typeof hash[1] !== 'undefined' && hash[1] !== null)
url += '#' + hash[1];
return url;
}
else
return url;
}
}
});

View File

@@ -0,0 +1,71 @@
require(['gitbook', 'jquery'], function(gitbook, $) {
function site(label, icon, link) {
return {
label: label,
icon: 'fa fa-' + icon,
onClick: function (e) {
e.preventDefault();
window.open(link);
}
};
}
var url = encodeURIComponent(location.href);
var title = encodeURIComponent(document.title);
var SITES = {
douban: site('豆瓣', 'share', 'http://shuo.douban.com/!service/share?href=' + url + '&name=' + title),
facebook: site('Facebook', 'facebook', 'http://www.facebook.com/sharer/sharer.php?s=100&p[url]=' + url),
google: site('Google+', 'google-plus', 'https://plus.google.com/share?url=' + url),
hatenaBookmark: site('はてなブックマーク', 'bold', 'http://b.hatena.ne.jp/entry/' + url),
instapaper: site('instapaper', 'instapaper', 'http://www.instapaper.com/text?u=' + url),
line: site('LINE', 'comment', 'http://line.me/R/msg/text/?' + title + ' ' + url),
linkedin: site('Linkedin', 'linkedin', 'https://www.linkedin.com/shareArticle?mini=true&url=' + url),
messenger: site('Facebook Messenger', 'commenting', 'fb-messenger://share?link=' + url),
pocket: site('Pocket', 'get-pocket', 'https://getpocket.com/save?url=' + url + '&title=' + title),
qq: site('QQ', 'qq', 'http://connect.qq.com/widget/shareqq/index.html?url=' + url + '&title=' + title),
qzone: site('QQ空间', 'star', 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' + url + '&title=' + title),
stumbleupon: site('StumbleUpon', 'stumbleupon', 'http://www.stumbleupon.com/submit?url=' + url + '&title=' + title),
twitter: site('Twitter', 'twitter', 'https://twitter.com/intent/tweet?url=' + title + '&text=' + title),
viber: site('Viber', 'volume-control-phone', 'viber://forward?text='+ url + ' ' + title),
vk: site('VK', 'vk', 'http://vkontakte.ru/share.php?url=' + url),
weibo: site('新浪微博', 'weibo', 'http://service.weibo.com/share/share.php?content=utf-8&url=' + url + '&title=' + title),
whatsapp: site('WhatsApp', 'whatsapp', 'whatsapp://send?text='+ url + ' ' + title),
};
gitbook.events.bind('start', function(e, config) {
var opts = config.sharing;
// Create dropdown menu
var menu = $.map(opts.all, function(id) {
var site = SITES[id];
return {
text: site.label,
onClick: site.onClick
};
});
// Create main button with dropdown
if (menu.length > 0) {
gitbook.toolbar.createButton({
icon: 'fa fa-share-alt',
label: 'Share',
position: 'right',
dropdown: [menu]
});
}
// Direct actions to share
$.each(SITES, function(sideId, site) {
if (!opts[sideId]) return;
gitbook.toolbar.createButton({
icon: site.icon,
label: site.text,
position: 'right',
onClick: site.onClick
});
});
});
});

4
docs/gitbook/gitbook.js Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Some files were not shown because too many files have changed in this diff Show More