1
mirror of https://github.com/nilaoda/N_m3u8DL-CLI synced 2025-09-07 02:45:59 +02:00

Compare commits

...

48 Commits

Author SHA1 Message Date
nilaoda
2446a25b35 Create LICENSE 2019-09-10 11:58:37 +08:00
nilaoda
d37524180d Update README.md 2019-09-10 11:21:59 +08:00
nilaoda
b02a29fbb7 更新文档 2019-09-09 17:22:59 +08:00
nilaoda
e87d02230d Merge branch 'master' of https://github.com/nilaoda/N_m3u8DL-CLI 2019-09-09 17:20:08 +08:00
nilaoda
63609a0970 增加--enableAudioOnly 2019-09-09 17:19:47 +08:00
nilaoda
1fe798ab19 Update README.md 2019-09-08 22:40:36 +08:00
nilaoda
21b9977501 Update README.md 2019-09-08 22:40:01 +08:00
nilaoda
fbe37be499 更新截图 2019-09-08 22:17:37 +08:00
nilaoda
6416dd642d 更新爱奇艺4K-H264 2019-08-27 01:52:23 +08:00
nilaoda
967f0582a6 修复台湾爱奇艺杜比 2019-08-25 00:02:02 +08:00
nilaoda
a5aeffc6ec 更新js 2019-08-24 23:09:25 +08:00
nilaoda
745cbd92ad 更新文档 2019-08-22 23:26:29 +08:00
nilaoda
4a4412a262 常规更新 2019-08-21 14:55:24 +08:00
nilaoda
084989b3ce update js 2019-08-11 23:38:52 +08:00
nilaoda
640208d95c 增加wetv字幕js 2019-08-11 23:31:33 +08:00
nilaoda
ad148ba4c7 更新芒果TV 2019-08-08 21:47:54 +08:00
nilaoda
7c961dbbbf 修正文档日期 2019-08-08 21:12:34 +08:00
nilaoda
83df7b4301 增加爱奇艺1080P H265 2019-08-08 21:08:41 +08:00
nilaoda
860282a463 支持愛奇藝 2019-08-07 12:06:07 +08:00
nilaoda
70582029dd 修复爱奇艺4K_H264 2019-08-07 11:23:53 +08:00
nilaoda
1f3002ef66 更新爱奇艺4K264、4K265代码 2019-08-07 10:21:56 +08:00
nilaoda
07c758dd00 增加爱奇艺杜比音轨JS 2019-08-07 02:09:59 +08:00
nilaoda
38f2f5589f 更新爱奇艺JS 2019-08-04 23:58:34 +08:00
nilaoda
c7b9414613 更新说明书 2019-07-24 00:45:03 +08:00
nilaoda
84953fa16a 更新爱奇艺JS 2019-07-14 21:43:03 +08:00
nilaoda
4cf88711d6 更新爱奇艺JS 2019-07-13 19:11:54 +08:00
nilaoda
b59940f719 修正错别字 2019-07-10 23:54:30 +08:00
nilaoda
6a6a338868 增加阿里云大学教程 2019-07-10 23:51:03 +08:00
nilaoda
0d74380e1c 更新文档 2019-07-10 22:42:30 +08:00
nilaoda
5a398bdb79 更新文档 2019-07-10 22:40:36 +08:00
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
59 changed files with 7776 additions and 60 deletions

21
LICENSE Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019 nilaoda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

File diff suppressed because one or more lines are too long

643
docs/Advanced.html Normal file

File diff suppressed because it is too large Load Diff

532
docs/GetM3u8.html Normal file

File diff suppressed because one or more lines are too long

492
docs/Introductory.html Normal file

File diff suppressed because it is too large Load Diff

501
docs/LinetvParser.html Normal file

File diff suppressed because it is too large Load Diff

495
docs/M3U8URL2File.html Normal file

File diff suppressed because it is too large Load Diff

507
docs/SimpleGUI.html Normal file

File diff suppressed because it is too large Load Diff

502
docs/ViuParser.html Normal file

File diff suppressed because it is too large Load Diff

507
docs/aliyunEdu.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;
}
}
});

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