1 >
返回列表 发新帖 回复

[程序咨询] how to make WeimengCMS support

楼主
查看 3847 回复 2| 发表于 2021-03-27 17:34:16

This example code will make read page to support multi-content include chapter content, manga and video embed.

$(document).ready(function(){
var html = '';
let vrx = /[-w]{16}/g; // Change your regex to what video host you want to detect
let prx = /(http(s?):)([/|.|w|s|-])*.(?:jpg|gif|png)/g; // Change your regex to what image host you want to detect
var content = `{已订阅}{章节内容}{/已订阅}`; // Content to detect
var vlink = content.match(vrx); //Detect Video with regex
var plink = content.match(prx); //Detect Images with regex

if (plink != null) {
for(var i in plink){
html += '<div style="margin-bottom: 15px;"><img class="center" width="100%" src="'+plink[i]+'" /></div>';
}
} else if (vlink != null) {
html += '<iframe name="videoframe" id="videoframe" src="'+vlink+'" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen=""></iframe>';
}
else {
content = content.replace(/(<br[s]*/?>[s]*)+/g, '<br/><br/>');// Remove <br/> tag if more than 1 and replace them
html += content;
}
$('.content').html(html);// Change to DIV you want them to appear
});
沙发
发表于 2021-03-29 13:10:23

Update

- Support iframe from Youtube, OK.RU, Google Drive and Fembed.


<div class="read z-depth-3" oncontextmenu="return false" onselectstart="return false" ondragstart="return false">
<div class="content noselect"></div>
</div>
<div class="video z-depth-3">
<ul class="tabs" id="tabs_swipe">
<li class="tab col s3"><a href="#google" class="trn">Google Drive</a></li>
<li class="tab col s3"><a href="#fembed" class="trn">Fembed</a></li>
<li class="tab col s3"><a href="#okru" class="trn">OK.RU</a></li>
<li class="tab col s3"><a href="#youtube" class="trn">Youtube</a></li>
</ul>
<div id="google" class="col s12"><p style="font-size: 2em; text-align: center;">ไม่มีข้อมูล</p></div>
<div id="fembed" class="col s12"><p style="font-size: 2em; text-align: center;">ไม่มีข้อมูล</p></div>
<div id="okru" class="col s12"><p style="font-size: 2em; text-align: center;">ไม่มีข้อมูล</p></div>
<div id="youtube" class="col s12"><p style="font-size: 2em; text-align: center;">ไม่มีข้อมูล</p></div>
</div>



<script>
$(document).ready(function(){
var html = '';
let youtube = /youtu.be|youtube.com/g;
let google = /google.com/g;
let fembed = /fembed.com/g;
let ok = /ok.ru/g;
let prx = /(http(s?):)([/|.|w|s|-])*.(?:jpg|gif|png)/g;
var content = `{已订阅}{章节内容}{/已订阅}`;
var link = content.split("<br/>");
for (var i in link){
if (link[i].match(prx)) {
html += '<div style="margin-bottom: 15px;"><img class="lazy center" width="100%" src="{templates}/static/image/book.svg" data-src="'+link[i]+'" /></div>';
$('.content').html(html);
$(".chapter_info,.video").hide();
} else if (link[i].match(youtube)) {
ytlink = link[i].match(/[a-zA-Z0-9_-]{11}/g);
html = '<div class="player"><iframe src="https://www.youtube.com/embed/'+ytlink+'" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div>';
$('#youtube').html(html);
$(".chapter_info,.read").hide();
} else if (link[i].match(google)) {
gglink = link[i].match(/([w-]){33}|([w-]){19}/g);
html = '<div class="player"><iframe src="https://drive.google.com/file/d/'+gglink+'/preview"></iframe></div>';
$('#google').html(html);
$(".chapter_info,.read").hide();
} else if (link[i].match(fembed)) {
femlink = link[i].match(/[a-zA-Z0-9_-]{15}/g);
html = '<div class="player"><iframe src="https://www.fembed.com/v/'+femlink+'" frameborder="0" allowfullscreen></iframe></div>';
$('#fembed').html(html);
$(".chapter_info,.read").hide();
} else if (link[i].match(ok)) {
oklink = link[i].match(/[0-9_-]{13}/g);
html = '<div class="player"><iframe src="//ok.ru/videoembed/'+oklink+'?nochat=1" frameborder="0" allow="autoplay" allowfullscreen></iframe></div>';
$('#okru').html(html);
$(".chapter_info,.read").hide();
} else if (link[i] != link[i].match(/(http(s?):)/g)){
$(".video").hide();
html = content.replace(/(<br[s]*/?>[s]*)+/g, '<br/><br/>');
$('.content').html(html);
} else {
break;
}
}
});
</script>


板凳
发表于 2021-03-29 15:25:24

Good Job,Thank you for your contribution to WMCMS

1 >
返回列表
您需要登录后才可以回帖 登录 | 注册