Created
August 25, 2024 21:13
-
-
Save rostok/c7a451e6398603c69b38940b07f17044 to your computer and use it in GitHub Desktop.
imdb-names command for UbiChr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UbiChr 'imdb-names' command | |
CmdUtils.CreateCommand({ | |
name:"imdb-names", | |
description:"Searches for actors on IMDb", | |
author:{}, | |
icon:"http://www.imdb.com/favicon.ico", | |
homepage:"", | |
license:"", | |
preview:async function define_preview(pblock, {text: text}) { | |
pblock.innerHTML = "Searches for movies on IMDb"; | |
if (text.trim()!="") { | |
jQuery(pblock).loadAbs("http://www.imdb.com/find?q="+encodeURIComponent(text)+"&s=nm&ref_=fn_al_tt_mr ul.ipc-metadata-list", ()=>{ | |
$(pblock).find('li').css('list-style-type', 'none').each(function() { | |
// Get the necessary data from the existing elements | |
var link = $(this).find('a').attr('href'); | |
var imgSrc = $(this).find('img').attr('src'); | |
var imgAlt = $(this).find('img').attr('alt'); | |
var name = $(this).find('a').text(); | |
var details = $(this).find('ul > li > span').text(); | |
if (typeof imgSrc === 'undefined') imgSrc = 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='; | |
// Set data-option and data-option-value attributes | |
$(this).attr('data-option', name); | |
$(this).attr('data-option-value', link); | |
// Clear out the contents of the LI | |
$(this).empty().append( | |
'<div style="display: table; width: 100%;">' + | |
'<div style="display: table-cell; width: 50px; vertical-align: top;">' + | |
'<img src="' + imgSrc + '" alt="' + imgAlt + '" width="50" height="50">' + | |
'</div>' + | |
'<div style="display: table-cell; vertical-align: top; padding-left: 10px;">' + | |
'<div style="font-weight: bold; margin-bottom: 5px;"><a href="' + link + '">' + name + '</a></div>' + | |
'<div>' + details + '</div>' + | |
'</div>' + | |
'</div>' | |
); | |
}); | |
}); | |
} | |
}, | |
execute:function execute(args) { | |
var opt = args._opt_val || ""; | |
if(opt.includes("://")) | |
CmdUtils.addTab(opt); | |
else | |
args._cmd.old_execute(args); | |
}, | |
old_execute:function(directObj) { | |
if (!directObj) return; | |
var opt = directObj._opt_val || ""; | |
if(opt.includes("://")) { | |
CmdUtils.addTab(opt); | |
} | |
else { | |
var text = directObj.text; | |
text = encodeURIComponent(text); | |
var finalurl = url; | |
finalurl = finalurl.replace(/\{text}|\{QUERY\}/g, text); | |
finalurl = finalurl.replace(/\{location\}/g, CmdUtils.getLocation()); | |
CmdUtils.addTab(finalurl); | |
} | |
}, | |
names:["imdb-names"] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment