Request dari Bulan Maret kemarin akhirnya ku kerjain karena butuh juga untuk theme database ku nantinya.
Demo : Click Disini
Style.css :
#resLive.active{opacity:1;height:200px;}
#resLive{opacity:0;height:0;background:rgb(21 32 43);color:white;border-radius:4px;height:0;overflow-y:scroll;position:relative;transition:opacity .3s ease-out;position:absolute;top:46px;width:100%;}
#resLive .infoLoading{text-align:center;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);font-weight:800;font-size:21px;}
#resLive div a {display: flex;align-items: center;gap: 12px;font-size: 18px;}
#resLive div img {width: 64px;height: 64px;object-fit: cover;border-radius: 50%;}
#resLive div.Item {margin: 12px 0;padding:12px;}
#resLive div.Item:hover{background:rgb(13 23 33);}
#resLive div.Item:nth-child(1){margin:0;}
#resLive div.Item:nth-last-child(1):not(#demo div.Item:nth-child(1)) {margin: 12px 0 0;}
Untuk Markup HTML engga ada yang special ckup cari form input querynya lalu tambahkan class.
liveSearch
Habis itu tambahkan Markup HTML dibawahnya.
Markup HTML :
<div id="resLive"></div>
Sehabis itu cek bahwa form input kalian ada css position relative karena Markup HTML yang kalian tambhakan tersebut terdapat css position absolute. ini bertujuan agar letak hasil liveSearchnya tidak kemana2.
Script.js :
$('.liveSearch').each(function(){
const uri = 'https://streaming-anime-indo.blogspot.com',
arr = [],
get = '';
let res = 0;
$(this).on('click input',function(){
if(res == 0){
$.ajax({
type:"GET",
url: uri + '/feeds/posts/default',
data:{alt:"json","max-results":0},
dataType:"jsonp",
success:function(e){
let l=e.feed.openSearch$totalResults.$t,
c = l%150==0?l/150-1:Math.floor(l/150);
if(l>res){
$('#resLive').addClass('active');
$('#resLive').html('<div class="infoLoading">Getting Data (<span>0.0%</span>)</div>');
for(let o=0;o<=c;o++){
$.ajax({
type:"GET",
url:uri + '/feeds/posts/default',
data:{alt:"json","start-index":150*o+1,"max-results":150},
dataType:"jsonp",
success:function(e){
for(let i=0;i<e.feed.entry.length+1;i++){
if(l>res){
const obj = {},feed = e.feed.entry[i];
obj['title'] = feed.title.$t;
const content = feed.content != null ? feed.content.$t : feed.summary.$t,
d=content.indexOf("<img"),
o=content.indexOf('src="',d) > -1 ? content.indexOf('src="',d) : content.indexOf("src='",d),
f=content.indexOf('"',o+5) > -1 ? content.indexOf('"',o+5) : content.indexOf("'",o+5),
g=content.substr(e+5,f-e-5),
imgs=-1!=d&&-1!=o&&-1!=f&&""!=g?g:"https://images.bizlaw.id/gbr_artikel/images-2_294.webp";
obj['img'] = feed.media$thumbnail != null ? feed.media$thumbnail.url.replace(/s72-c/,'s500') : imgs;
for(let x=0;x<feed.link.length;x++){
obj['url'] = feed.link[x].href;
}
arr.push(obj);
res++;
$('#resLive .infoLoading span').html(((res/l)*100).toFixed(1) + '%');
}else{
$('#resLive').html('<div class="infoLoading">Waiting You Type...</div>');}
}
}})
}
}else{
if($('#resLive div').length == 0){
$('#resLive').html('<div class="infoLoading">Waiting You Type...</div>');
}
}
}})
}
});
$(this).keyup(function(){
let query = $(this).val(),
get = '';
if(query != ''){
$('#resLive').addClass('active');
for(let e=0;e<arr.length;e++){
if(arr[e].title.toUpperCase().search(query.toUpperCase()) > -1){
get += '<div class="Item"><a href="'+arr[e].url+'">'
+ '<img loading="lazy" alt="'+arr[e].title+'" src="'+arr[e].img+'">'
+ '<span>'+arr[e].title+'</span>'
+'</a></div>';
}
}
if(get.length != 0){
$('#resLive').html(get);
}else{
$('#resLive').html('<div class="infoLoading">No Result...</div>');
}
}else{
$('#resLive').removeClass('active');
$('#resLive').html('');
}
});
});
Note :
- Gunakan Jquery Library.
- Ubah uri di script dengan url kalian atau bisa gunakan ini.
const uri = location.protocol + '//' + location.hostname,
Karena didemo ada di theme zeist maka ini source untuk zeist :
style.css :
#resLive.active{opacity:1;height:200px;z-index: 999999;}
#resLive{opacity:0;height:0;background:rgb(21 32 43);color:white;border-radius:4px;height:0;overflow-y:scroll;position:relative;transition:opacity .3s ease-out;position:absolute;top:46px;width:100%;}
#resLive .infoLoading{text-align:center;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);font-weight:800;font-size:13px;}
#resLive div a {display: flex;align-items: center;gap: 4px;font-size: 13px;}
#resLive div img {width: 28px;height: 28px;object-fit: cover;border-radius: 50%;}
#resLive div.Item {margin: 12px 0;padding:4px;cursor:pointer;}
#resLive div.Item:hover a span{color:var(--primary-color);}
#resLive div.Item:hover{background:rgb(13 23 33);}
#resLive div.Item:nth-child(1){margin:0;}
#resLive div.Item:nth-last-child(1):not(#demo div.Item:nth-child(1)) {margin: 12px 0 0;}
#resLive div a span {display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 1;overflow: hidden;color: white;}
$('.liveSearch').each(function(){
const uri = location.protocol + '//' + location.hostname,
arr = [],
get = '';
let res = 0;
$(this).on('click input',function(){
if(res == 0){
$.ajax({
type:"GET",
url: uri + '/feeds/posts/default',
data:{alt:"json","max-results":0},
dataType:"jsonp",
success:function(e){
let l=e.feed.openSearch$totalResults.$t,
c = l%150==0?l/150-1:Math.floor(l/150);
if(l>res){
$('#resLive').addClass('active');
$('#resLive').html('<div class="infoLoading">Getting Data (<span>0.0%</span>)</div>');
for(let o=0;o<=c;o++){
$.ajax({
type:"GET",
url:uri + '/feeds/posts/default',
data:{alt:"json","start-index":150*o+1,"max-results":150},
dataType:"jsonp",
success:function(e){
for(let i=0;i<e.feed.entry.length+1;i++){
if(l>res){
const obj = {},feed = e.feed.entry[i];
obj['title'] = feed.title.$t;
const content = feed.content != null ? feed.content.$t : feed.summary.$t,
d=content.indexOf("<img"),
o=content.indexOf('src="',d) > -1 ? content.indexOf('src="',d) : content.indexOf("src='",d),
f=content.indexOf('"',o+5) > -1 ? content.indexOf('"',o+5) : content.indexOf("'",o+5),
g=content.substr(e+5,f-e-5),
imgs=-1!=d&&-1!=o&&-1!=f&&""!=g?g:"https://images.bizlaw.id/gbr_artikel/images-2_294.webp";
obj['img'] = feed.media$thumbnail != null ? feed.media$thumbnail.url.replace(/s72-c/,'s500') : imgs;
for(let x=0;x<feed.link.length;x++){
obj['url'] = feed.link[x].href;
}
arr.push(obj);
res++;
$('#resLive .infoLoading span').html(((res/l)*100).toFixed(1) + '%');
}else{
$('#resLive').html('<div class="infoLoading">Waiting You Type...</div>');}
}
}})
}
}else{
if($('#resLive div').length == 0){
$('#resLive').html('<div class="infoLoading">Waiting You Type...</div>');
}
}
}})
}
});
$(this).keyup(function(){
let query = $(this).val(),
get = '';
if(query != ''){
$('#resLive').addClass('active');
for(let e=0;e<arr.length;e++){
if(arr[e].title.toUpperCase().search(query.toUpperCase()) > -1){
get += '<div class="Item"><a href="'+arr[e].url+'">'
+ '<img loading="lazy" alt="'+arr[e].title+'" src="'+arr[e].img+'">'
+ '<span>'+arr[e].title+'</span>'
+'</a></div>';
}
}
if(get.length != 0){
$('#resLive').html(get);
}else{
$('#resLive').html('<div class="infoLoading">No Result...</div>');
}
}else{
$('#resLive').removeClass('active');
$('#resLive').html('');
}
});
});
#resLive div img {width: 64px;height: 64px;object-fit: cover;border-radius: 50%;}
kalo kamu liatnya di demo itu memang kecil karena ngikutin si formnya. kalo di theme mu bakal besar nnti asal kamu kasih position relative pada formnya
untuk penambahan sinopsi teks bisa ku kerjain besok tpi kalo kamu mau coba sendiri tinggal gini
tambahkan ini di script.js pada bagian feed body :
obj['content'] = content;
lalu pada event key up kamu tinggal extrack datanya pada bagian loop get
arr[e].content
style :
#resLive.active{opacity:1;height:200px;}
#resLive{opacity:0;height:0;background:rgb(21 32 43);color:white;border-radius:4px;height:0;overflow-y:scroll;position:relative;transition:opacity .3s ease-out;position:absolute;top:46px;width:100%;}
#resLive .infoLoading{text-align:center;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);font-weight:800;font-size:21px;}
#resLive div a {display: flex;align-items: center;gap: 12px;font-size: 18px;}
#resLive div img {width: 64px;height: 64px;object-fit: cover;border-radius: 50%;}
#resLive div.metaData{flex:8;}
#resLive div.metaData p{margin:10px 0 0;font-size:14px;}
#resLive div.Item {margin: 12px 0;padding:12px;}
#resLive div.Item:hover{background:rgb(13 23 33);}
#resLive div.Item:nth-child(1){margin:0;}
#resLive div.Item:nth-last-child(1):not(#demo div.Item:nth-child(1)) {margin: 12px 0 0;}
$('.liveSearch').each(function(){
const uri = 'https://streaming-anime-indo.blogspot.com',
summaryLength = '120',
arr = [];
let res = 0;
$(this).on('click input',function(){
if(res == 0){
$.ajax({
type:"GET",
url: uri + '/feeds/posts/default',
data:{alt:"json","max-results":0},
dataType:"jsonp",
success:function(e){
let l=e.feed.openSearch$totalResults.$t,
c = l%150==0?l/150-1:Math.floor(l/150);
if(l>res){
$('#resLive').addClass('active');
$('#resLive').html('<div class="infoLoading">Getting Data (<span>0.0%</span>)</div>');
for(let o=0;o<=c;o++){
$.ajax({
type:"GET",
url:uri + '/feeds/posts/default',
data:{alt:"json","start-index":150*o+1,"max-results":150},
dataType:"jsonp",
success:function(e){
for(let i=0;i<e.feed.entry.length+1;i++){
if(l>res){
const obj = {},feed = e.feed.entry[i];
obj['title'] = feed.title.$t;
const content = feed.content != null ? feed.content.$t : feed.summary.$t,
d=content.indexOf("<img"),
o=content.indexOf('src="',d) > -1 ? content.indexOf('src="',d) : content.indexOf("src='",d),
f=content.indexOf('"',o+5) > -1 ? content.indexOf('"',o+5) : content.indexOf("'",o+5),
g=content.substr(e+5,f-e-5),
imgs=-1!=d&&-1!=o&&-1!=f&&""!=g?g:"https://images.bizlaw.id/gbr_artikel/images-2_294.webp";
obj['img'] = feed.media$thumbnail != null ? feed.media$thumbnail.url.replace(/s72-c/,'s500') : imgs;
obj['synopsy'] = content.replace(/(<([^>]+)>)/ig,'');
for(let x=0;x<feed.link.length;x++){
obj['url'] = feed.link[x].href;
}
arr.push(obj);
res++;
$('#resLive .infoLoading span').html(((res/l)*100).toFixed(1) + '%');
}else{
$('#resLive').html('<div class="infoLoading">Waiting You Type...</div>');}
}
}})
}
}else{
if($('#resLive div').length == 0){
$('#resLive').html('<div class="infoLoading">Waiting You Type...</div>');
}
}
}})
}
});
$(this).keyup(function(){
let query = $(this).val(),
get = '';
if(query != ''){
$('#resLive').addClass('active');
for(let e=0;e<arr.length;e++){
if(arr[e].title.toUpperCase().search(query.toUpperCase()) > -1){
get += '<div class="Item"><a href="'+arr[e].url+'">'
+ '<img loading="lazy" alt="'+arr[e].title+'" src="'+arr[e].img+'">'
+ '<div class="metaData"><span>'+arr[e].title+'</span>'
+ '<p>' + arr[e].synopsy.slice(0,summaryLength) + '...</span></div>'
+'</a></div>';
}
}
if(get.length != 0){
$('#resLive').html(get);
}else{
$('#resLive').html('<div class="infoLoading">No Result...</div>');
}
}else{
$('#resLive').removeClass('active');
$('#resLive').html('');
}
});
});
kamu tinggal setting SummaryLength untuk menampilkan berapa panjang synopsinya
Btw, sudah selesai berapa % temamu?
misalnya kyak logic license theme product yang ku integration ke situs utama nantinya,
karena risk an kalo product theme blogger. kalo ga dikasih license (meskipun gratis ya themenya) takutnya ada oknum yg ngejualnya ke orang awam ataupun kalo product paid takutnya di jual ulang. ya begitulah intinya :D
var categArray = [];
for(let xa=0;xa<feed.category.length;xa++){
categArray.push(json.feed.category[xa].term);
var genre = categArray.filter(item => {
return item = 'Adventure' || item = 'Action';
});
var type = categArray.filter(item => {
return item = 'TV' || item = 'OVA';
});
}
obj['type'] = type;
obj['genre'] = genre;
lalu pada event keyUp kamu cari tag p di loop get
ubah arr[e].synopsy jadi
arr[e].type / arr[e].genre
btw itu spannya ubah p aja www ga liat aku masa gini
<p> ........ </span>
return item == 'TV' || item == 'OVA';
jadi "=" itu ada 2 kalo cuma 1 bakal ga filter
obj['synopsy'] = content.replace(/(<([^>]+)>)/ig,'');
categArray.push(feed.category[xa].term);
habis itu di resultnya ini
arr[e].type.slice(0,summaryLength)
kamu jadiin seperti ini :
arr[e].type
contoh :
arr[e].type.join(',')
contoh :
const getEps = 'Eps. 4';
document.getElementById('res').innerHTML = getEps.replace('Eps.','Ep');
dan kurang tepat seperti ketika input "i" ada The Down (2019) pdhal itu gada huruf i, lalu ketik "l" ada yg muncul Spider-Man: Far from Home (2019) padahal gada huruf "l"
ini kamu bisa minimalisir dengan condition title indexOf dsb apabila title mengandung kalimat pada input
nice lanjutkan lagi
for(let o=0;o<=c;o++)
/feeds/posts/default/-/Series
coba kamu pelajari itu tinggal kamu copy paste aja itu lalu inputin filter yg kamu mau kayak "HDTV" || "WEBDL" || "HDCam" dkk
coba kamu hilangin css ini ".mystyle"
nanti bakal muncul tpi form search mu bakal ancur/ga menarik di mobile
lalu pada bagian ".sm\:dn, #Query-input" di screen 900px jadiin display block hasilnya nnti bakal begini
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBCPHWdNEHP6UABRtZuJaMB4NQwxS8qBoZNh4XKkx2jYnZfzuqqiVrI6xtabO0BbdFtHESO_IqTnwwLFeboN-2TNVDfLZkNKb6hoUTjCqIbufKMEJ798QX9cBFYHMulFKI4uY6ePjWcD10L7cBAivmqg7lMEBzmhXzsobjbQpSBXHYYOVaihwXIbnq/s1366/bcd.png