User:Anpang/Wikipe-tan Chatbox.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | This user script seems to have a documentation page at User:Anpang/Wikipe-tan Chatbox and an accompanying .css page at User:Anpang/Wikipe-tan Chatbox.css. |
// get css
importStylesheet("User:Anpang01/Wikipe-tan_Chatbox.css");
// add box
$("body").append(`
<div class="wptc-box" id="wptc-box">
<div>
<img src="/media/wikipedia/commons/a/ac/Wikipe-tan_head.png" class="wptc-image" />
<span class="wptc-name">Wikipe-tan</span>
<a href="#" class="wptc-close" id="wptc-close">×</a>
</div>
<div class="wptc-inner-box">
<div id="wptc-inner-box">
<div class="wptc-bubble-left">
<span>Hello</span>
</div>
<div class="wptc-bubble-right">
<span>Hello</span>
</div>
<input type="text" class="wptc-input" id="wptc-input" />
</div>
</div>
<span class="wptc-bottom-links">
 
<a href="https://en.wikipedia.org/wiki/User:Anpang01/Wikipe-tan_Chatbox">JS script</a>
 
<a href="https://en.wikipedia.org/wiki/Wikipedia:Wikipe-tan">Based on Wikipe-tan</a>
 
</span>
</div>
`);
// close box handler
$("#wptc-close").on("click", function() {
$("#wptc-box").hide();
});
// get response
function wptcGetResponse(input) {
return "test";
}
// submit handler
$("#wptc-input").keypress(function(key) {
if(key.which === 13) { // is enter key
// get and clear input
input = $("wptc-input").val("");
// do stuff
$("#wptc-inner-box").append(`
<div class="wptc-bubble-right">
<span>${input}</span>
</div>
<div class="wptc-bubble-left">
<span>${wptcGetResponse(input)}</span>
</div>
`);
}
});