由于想使用typecho的博客播放一些视频,经过搜索得到了DPlayer这个插件。记录一下安装步骤
- 安装DPlayer
项目地址为:https://github.com/DIYgod/DPlayer ,从这里下载最新版本的DPlayer 插件 然后放置到plugins 目录下,并且在后台启用这个插件。 - 添加Header
在主题的header.php文件的header结束标签前 加入如下这段代码<script> // DPlayer API document.addEventListener('DOMContentLoaded', initDplayer); function initDplayer() { const common = { loadResource: function (id, resource, type, callback) { let loaded = document.head.querySelector('#' + id); if (loaded) { callback(); return; } const element = document.createElement(type); element.onload = element.onreadystatechange = () => { if (!loaded && (!element.readyState || /loaded|complete/.test(element.readyState))) { element.onload = element.onreadystatechange = null; loaded = true; callback(); } } if (type === 'link') { element.rel = 'stylesheet'; element.href = resource; } else { element.src = resource; } element.id = id; document.getElementsByTagName('head')[0].appendChild(element); }, loadResources: function (callback) { const cdn = '//s0.pstatp.com/cdn/expire-1-M'; const resources = [ '/dplayer/1.25.0/DPlayer.min.css', '/dplayer/1.25.0/DPlayer.min.js', '/hls.js/0.12.4/hls.light.min.js', '/flv.js/1.5.0/flv.min.js' ]; let unloadedResourceCount = resources.length; resources.forEach(resource => { this.loadResource(btoa(resource).replace(/[=+\/]/g, ''), cdn + resource, ({ 'css': 'link', 'js': 'script' })[resource.split('.').pop()], () => --unloadedResourceCount ? null : callback() ); }); }, createDplayers: function (sources, callback) { for (let i = 0; i < sources.length; i++) { const child = document.createElement('div'); const src = sources[i].getAttribute('src'); sources[i].parentNode.insertBefore(child, sources[i]); sources[i].style.display = 'none'; const type = src.split('.').pop(); const option = { url: src }; type === 'flv' ? option.type = type : null; const dplayer = new DPlayer({ container: child, preload: 'none', autoplay: false, screenshot: false, video: option }); } if (typeof callback === 'function') callback(); } }; const mirages = { isMirages: function () { return window.Mirages || false }, fixVideoSize: function (length) { let outerTimer = false; const outerInterval = setInterval(() => { if (outerTimer) return; const videos = document.getElementsByTagName('video'); if (videos.length === length) { const dplayerWraps = document.querySelectorAll('.dplayer-video-wrap'); for (let i = 0; i < length; i++) { const videoContainers = dplayerWraps[i].querySelectorAll('.video-container.video-4-3'); if (videoContainers.length) { videoContainers[0].style = 'position: initial;'; videoContainers[0].className = 'video-container video-16-9'; console.log('video-4-3 fixed.'); } else { const videoContainer = document.createElement('div'); videoContainer.style = 'position: initial;'; videoContainer.className = 'video-container video-16-9'; videoContainer.appendChild(videos[i]); dplayerWraps[i].appendChild(videoContainer); console.log('video-16-9 inserted.'); const targetNode = videoContainer; const config = { childList: true }; const callback = (mutationsList, observer) => { const newVideoContainers = videoContainer.querySelectorAll( '.video-container.video-4-3'); if (newVideoContainers.length) { newVideoContainers[0].className = ''; console.log('auto inserted video-4-3 fixed.'); observer.disconnect(); } }; const observer = new MutationObserver(callback); observer.observe(targetNode, config); setTimeout(() => observer.disconnect(), 1000 * 120); } } outerTimer = true; clearInterval(outerInterval); } }, 500); } }; const dps = document.getElementsByTagName('dp'); if (dps.length !== 0) { common.loadResources(() => common.createDplayers(dps, () => { mirages.isMirages() ? mirages.fixVideoSize(dps.length) : null; })); } }; </script>
然后关闭pjax。
- 加入视频测试
在文章中使用如下代码即可添加视频<dp src=""></dp>
You actually stated this terrifically!
[url=https://researchproposalforphd.com/]college term papers for sale[/url] term paper help [url=https://writingresearchtermpaperservice.com/]buy research paper online[/url] research proposal apa
Thank you. Quite a lot of knowledge.
proposal for phd writing services for research papers research proposal introduction proposal writer
[url=https://researchproposalforphd.com/]research proposal help[/url] best research paper writing services [url=https://writingresearchtermpaperservice.com/]research proposal help[/url] research papers help
dissertation guide https://ouressays.com
This is nicely put. .
[url=https://essaypromaster.com/]writing a research paper[/url] pay for a paper [url=https://paperwritingservicecheap.com/]online essay writers[/url] writing my paper for me
Thank you. Quite a lot of content.
good thesis argumentative thesis thesis writing service uk thesis guidelines
Appreciate it. Quite a lot of knowledge!
essay service urgent essay writing service essay writing service uk essay writing help
[url=https://ouressays.com/]research paper writing help[/url] essay proposal [url=https://researchpaperwriterservices.com/]buy college research papers[/url] custom research papers
cheap essay writing https://buyanessayscheaponline.com
Beneficial write ups. Kudos.
uk dissertation writing writing a phd dissertation dissertation editing help writing dissertation proposal
[url=https://bestpaperwritingservice.com/]custom written college papers[/url] online research paper writing service [url=https://bestonlinepaperwritingservices.com/]buy college paper online[/url] custom paper writers
custom writing bay https://custompaperwritingservices.com
Tips certainly used..
[url=https://topswritingservices.com/]cheap essay writing[/url] essay writing service blog [url=https://essaywriting4you.com/]buy essay writing online[/url] essay writing service reddit
Many thanks. I like this.
[url=https://writinganessaycollegeservice.com/]cheap essay writing[/url] best online essay writing service [url=https://essayservicehelp.com/]essay writing site[/url] essay writing
Useful forum posts. With thanks.
top executive resume writing service essay paper writing service press release writing service paper writing service
You actually reported this really well!
research paper writer services cheap research paper writing service term papers elements of a research proposal
[url=https://helpwithdissertationwriting.com/]proquest dissertations[/url] best dissertation [url=https://dissertationwritingtops.com/]dissertation writing services reviews[/url] definition of dissertation
research paper thesis https://bestpaperwritingservice.com
what bitcoins are accepted by darknet markets darknet market list [url=https://cyphermarket-url.com/ ]darknet market alaska [/url]
Very good postings, Appreciate it!
essay writting service types of essay writing best essay writing service review best college paper writing service
[url=https://domyhomeworkformecheap.com/]my homework[/url] pay someone to do my homework [url=https://domycollegehomeworkforme.com/]should i do my homework[/url] cpm homework
professional report writing services https://bestpaperwritingservice.com
Wonderful facts, Regards!
[url=https://essaywritingservicehelp.com/]is essay writing service legal[/url] best essay writing service [url=https://essaywritingservicebbc.com/]college essay writing help[/url] professional paper writing services
Awesome data. Cheers.
[url=https://bestpaperwritingservice.com/]custom research paper writing services[/url] pay for research paper [url=https://bestonlinepaperwritingservices.com/]cheap research paper writing service[/url] paper writing service
Fine facts. Kudos.
essay writing service cheap education essay writing service article writing service admission essay service
You've made your stand quite nicely!!
best paper writing services unique essay writing service custom dissertation writing service essay writing in english
You said it perfectly..
buy an essay pay to write essay essay for sale pay for essay papers
You reported that exceptionally well!
[url=https://essaywritingservicelinked.com/]college admissions essay writing service[/url] essay writing site [url=https://essaywritingservicetop.com/]cheap essay writing service[/url] essay service reviews
Fantastic postings, Many thanks!
medical school personal statement cheap essay help helping others essay essaytyper
[url=https://phdthesisdissertation.com/]define dissertation[/url] buy dissertations [url=https://writeadissertation.com/]dissertation writing services reviews[/url] writing dissertations
write an argument essay https://essaywritingservicehelp.com
Cheers. I like this!
writing a narrative essay service to others essay buy essay writing online argumentative essay writing
[url=https://homeworkcourseworkhelps.com/]online coursework[/url] i don t want to do my homework [url=https://helpmedomyxyzhomework.com/]homework help[/url] hire someone to do my homework
buying essays online https://dissertationwritingtops.com