Posted in API and Javascript
291
4:06 am, March 15, 2022
 

Love Like Dislike API and Javascript

<h3>Working Example Full Page</h3>
<p>You can check it out below, just include the script and it records the details based on the current URL.&nbsp;</p>
<p><a class="btn btn-info" href="https://kruxor.com/lovelike/" target="blank" rel="noopener">Love Like API Demo</a></p>
<p><a href="https://kruxor.com/lovelike/"><img style="display: block; margin-left: auto; margin-right: auto;" src="https://i.imgur.com/fFq6wFA.png" /></a></p>
<h3>Quick Embed</h3>
<p>Add this to the page where you would like the icons and likes to appear.&nbsp;</p>
<h4>HTML</h4>
<pre><code class="html hljs xml">&lt;div id="love
like"&gt;&amp;nbsp;&lt;/div&gt;&lt;script src="https://api.kruxor.com/js/lovelike.js"&gt;&lt;/script&gt;</code></pre>
<h3>&nbsp;</h3>
<h3>The Idea</h3>
<p>An API that allows a url to have love, like or dislike's attached to it.&nbsp;</p>
<p>Quite simple layout.&nbsp;</p>
<p>url, lovenum, likenum, dislikenum</p>
<p>then have a way to send the nums, and update the buttons with the number.&nbsp;</p>
<p>just include a script on the page and it will do the rest, show the buttons, and current stats.&nbsp;</p>
<h3>Demo</h3>
<p><img src="https://i.imgur.com/2zcnqqx.gif" /></p>
<h3>Structure</h3>
<p><img src="https://i.imgur.com/ndM1CTV.png" /></p>
<h3>Script</h3>
<p><a href="https://api.kruxor.com/js/lovelike.js">/js/lovelike.js</a></p>
<p>This script needs to, write to the page the love, like dislike buttons.</p>
<p>allow turning on and off of buttons</p>
<p>send click data to the api, will need a way of updating this via php callback via ajax.</p>
<p>load the existing values from the api data for the url</p>
<h3>Get the Icons</h3>
<p>Try icons from : <a href="https://heroicons.com/">https://heroicons.com/</a>&nbsp;</p>
<p>Love:&nbsp;</p>
<p><code>&lt;svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor"&gt;</code><br /><code>&nbsp; &lt;path fill-rule="evenodd" d="M3.172 5.172a4 4 0 015.656 0L10 6.343l1.172-1.171a4 4 0 115.656 5.656L10 17.657l-6.828-6.829a4 4 0 010-5.656z" clip-rule="evenodd" /&gt;</code><br /><code>&lt;/svg&gt;</code></p>
<p>Like:&nbsp;</p>
<p><code>&lt;svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor"&gt;</code><br /><code>&nbsp; &lt;path d="M2 10.5a1.5 1.5 0 113 0v6a1.5 1.5 0 01-3 0v-6zM6 10.333v5.43a2 2 0 001.106 1.79l.05.025A4 4 0 008.943 18h5.416a2 2 0 001.962-1.608l1.2-6A2 2 0 0015.56 8H12V4a2 2 0 00-2-2 1 1 0 00-1 1v.667a4 4 0 01-.8 2.4L6.8 7.933a4 4 0 00-.8 2.4z" /&gt;</code><br /><code>&lt;/svg&gt;</code></p>
<p>Dislike:&nbsp;</p>
<p><code>&lt;svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor"&gt;</code><br /><code>&nbsp; &lt;path d="M18 9.5a1.5 1.5 0 11-3 0v-6a1.5 1.5 0 013 0v6zM14 9.667v-5.43a2 2 0 00-1.105-1.79l-.05-.025A4 4 0 0011.055 2H5.64a2 2 0 00-1.962 1.608l-1.2 6A2 2 0 004.44 12H8v4a2 2 0 002 2 1 1 0 001-1v-.667a4 4 0 01.8-2.4l1.4-1.866a4 4 0 00.8-2.4z" /&gt;</code><br /><code>&lt;/svg&gt;</code></p>
<h3>Write the buttons to the page</h3>
<p><code>/ draw the buttons on the page /</code><br /><code>/ &lt;div id="lovelike"&gt;&amp;nbsp;&lt;/div&gt;
/</code><br /><code>function kxdrawbuttons() {</code><br /><code>&nbsp; var kxbuttons = &lt;style&gt;.kx-buttons {</code><br /><code>&nbsp; &nbsp; padding:10px;</code><br /><code>&nbsp; &nbsp; border-radius:5px;</code><br /><code>&nbsp; &nbsp; background:#000;</code><br /><code>&nbsp; &nbsp; position:absolute;</code><br /><code>&nbsp; }</code><br /><code>&nbsp; &lt;/style&gt;</code><br /><code>&nbsp; &lt;div class='kx-buttons'&gt;</code></p>
<p><code>&nbsp; &lt;/div&gt;
;</code><br /><code>&nbsp; document.getElementById("love
like").innerHTML = kxbuttons;</code><br /><code>}</code><br /><code>window.onload = function() {</code><br /><code>&nbsp; kxdrawbuttons();</code><br /><code>}</code></p>
<h3>Include Test Script</h3>
<p><code>&lt;div id="love
like"&gt;&amp;nbsp;&lt;/div&gt;&lt;script src="https://api.kruxor.com/js/lovelike.js"&gt;&lt;/script&gt;</code></p>
<p>Just adding text to start with, with the values.</p>
<p><span id="kxll" class="kx-love-label">Love:&nbsp;</span><span id="kxlv" class="kx-love-value">0</span>&nbsp;<span id="kxlil" class="kx-like-label">Like:</span>&nbsp;<span id="kxliv" class="kx-like-value">0</span>&nbsp;<span id="kxdl" class="kx-dislike-label">Dislike:</span>&nbsp;<span id="kxdv" class="kx-dislike-value">0</span></p>
<p><span class="kx-dislike-value">Then attach click events to each item, to allow a callback to the api to write the data back to the database.&nbsp;</span></p>
<p><span class="kx-dislike-value">Testing here: <a href="https://kruxor.com/view/code/OSUTE/test-love-like-dislike-script-from-api/">https://kruxor.com/view/code/OSUTE/test-love-like-dislike-script-from-api/</a>&nbsp;</span></p>
<h3><span class="kx-dislike-value">Read and Write Class Values</span></h3>
<p><span class="kx-dislike-value">Add a php script that loads the love like class and allows reading and writing to it.&nbsp;</span></p>
<p>callback.php</p>
<p><code>&lt;?php</code></p>
<p><code>errorreporting(EALL);</code><br /><code>iniset( 'displayerrors','1');</code></p>
<p><code>/ accept callbacks for api js's /</code></p>
<p><code>/ ?class=lovelike&amp;calltype=read</code></p>
<p><code>https://api.kruxor.com/callback.php?class=love
like&amp;calltype=read</code><br /><code>https://api.kruxor.com/callback.php?class=lovelike&amp;love=1&amp;like=0&amp;dislike=0&amp;url=test</code></p>
<p><code>Allowed Vars</code><br /><code>class = love
like</code><br /><code>calltype = write, read ?? does need this? prob not.</code></p>
<p><code>
/</code></p>
<p><code>if(!isset($GET['class'])) {</code><br /><code>&nbsp; return false;</code><br /><code>} else {</code><br /><code>&nbsp; // only allow certain classes to be called, otherwise anything can be written...</code><br /><code>&nbsp; $class = $GET['class'];</code><br /><code>&nbsp; // add additional allowed classes here...</code><br /><code>&nbsp; if($class === "lovelike") {</code><br /><code>&nbsp; &nbsp; // add additional classes to this if...</code><br /><code>&nbsp; } else {</code><br /><code>&nbsp; &nbsp; return false;</code><br /><code>&nbsp; }</code><br /><code>}</code></p>
<p><code>/</code><br /><code>if(!isset($GET['calltype'])) {</code><br /><code>&nbsp; return false;</code><br /><code>} else {</code><br /><code>&nbsp; $calltype = $GET['calltype'];</code><br /><code>}</code><br /><code>/</code></p>
<p><code>// try and start the class with no global inc</code><br /><code>include("class/core.class.php");</code><br /><code>include("class/functions.class.php");</code><br /><code>include("class/db.class.php"); // ???</code></p>
<p><code>// start required classes.&nbsp;</code><br /><code>$functions = new functions;</code></p>
<p><code>// check if the class exists for $class extend load.</code><br /><code>$class
filename = "class/extends/" . $class . ".extend.php";</code><br /><code>if(fileexists($classfilename)) {</code><br /><code>&nbsp; include($classfilename);</code><br /><code>} else {</code><br /><code>&nbsp; return false;</code><br /><code>}</code></p>
<p><code>$classstart = new $class;</code><br /><code>$classstart-&gt;start();</code></p>
<p><code>if($class === "lovelike") {</code></p>
<p><code>&nbsp; if(isset($
GET['url'])) {</code><br /><code>&nbsp; &nbsp; $url = $GET['url'];</code><br /><code>&nbsp; } else {</code><br /><code>&nbsp; &nbsp; return false; // need a url to continue</code><br /><code>&nbsp; }</code><br /><code>&nbsp; if(isset($GET['love'])) {</code><br /><code>&nbsp; &nbsp; $love = $GET['love'];</code><br /><code>&nbsp; &nbsp; // these must equal 1 only</code><br /><code>&nbsp; &nbsp; if($love &gt; 1) {</code><br /><code>&nbsp; &nbsp; &nbsp; return;</code><br /><code>&nbsp; &nbsp; }</code><br /><code>&nbsp; } else {</code><br /><code>&nbsp; &nbsp; $love = 0;</code><br /><code>&nbsp; }</code><br /><code>&nbsp; if(isset($GET['like'])) {</code><br /><code>&nbsp; &nbsp; $like = $GET['like'];</code><br /><code>&nbsp; &nbsp; if($like &gt; 1) {</code><br /><code>&nbsp; &nbsp; &nbsp; return;</code><br /><code>&nbsp; &nbsp; }</code><br /><code>&nbsp; } else {</code><br /><code>&nbsp; &nbsp; $like = 0;</code><br /><code>&nbsp; }</code><br /><code>&nbsp; if(isset($GET['dislike'])) {</code><br /><code>&nbsp; &nbsp; $dislike = $GET['dislike'];</code><br /><code>&nbsp; &nbsp; if($dislike &gt; 1) {</code><br /><code>&nbsp; &nbsp; &nbsp; return;</code><br /><code>&nbsp; &nbsp; }</code><br /><code>&nbsp; } else {</code><br /><code>&nbsp; &nbsp; $dislike = 0;</code><br /><code>&nbsp; }</code></p>
<p><code>&nbsp; // load from any match url.</code><br /><code>&nbsp; $fields
array = [</code><br /><code>&nbsp; &nbsp; "url" =&gt; $url,</code><br /><code>&nbsp; ];</code><br /><code>&nbsp; if($classstart-&gt;loadfromfieldsarray($fieldsarray, $max = 1)) {</code><br /><code>&nbsp; &nbsp; // we have a record and its loaded, otherwise add it.</code><br /><code>&nbsp; &nbsp; $classstart-&gt;love = $classstart-&gt;love + $love;</code><br /><code>&nbsp; &nbsp; $classstart-&gt;like = $classstart-&gt;like + $like;</code><br /><code>&nbsp; &nbsp; $classstart-&gt;dislike = $classstart-&gt;dislike + $dislike;</code><br /><code>&nbsp; &nbsp; $classstart-&gt;update();</code><br /><code>&nbsp; } else {</code><br /><code>&nbsp; &nbsp; $classstart-&gt;url = $url;</code><br /><code>&nbsp; &nbsp; $classstart-&gt;love = 0 + $love;</code><br /><code>&nbsp; &nbsp; $classstart-&gt;like = 0 + $like;</code><br /><code>&nbsp; &nbsp; $classstart-&gt;dislike = 0 + $dislike;</code><br /><code>&nbsp; &nbsp; $classstart-&gt;add();</code><br /><code>&nbsp; }</code></p>
<p><code>&nbsp; // return this data as an array that can be used to update the page.</code></p>
<p>&nbsp;</p>
<p><code>}</code></p>
<p><br /><code>echo $class
start-&gt;nicename;</code></p>
<p>&nbsp;</p>
<p><code>?&gt;</code></p>
<p>Callback is now writing data, just needs to return something useful.&nbsp;</p>
<p><a href="https://api.kruxor.com/callback.php?class=love
like&amp;love=1&amp;like=0&amp;dislike=0&amp;url=http://kruxor.com">https://api.kruxor.com/callback.php?class=lovelike&amp;love=1&amp;like=0&amp;dislike=0&amp;url=http://kruxor.com</a></p>
<h3>Love Like Javascript</h3>
<p><code>/ draw the buttons on the page /</code><br /><code>/ &lt;div id="lovelike"&gt;&amp;nbsp;&lt;/div&gt;
/</code><br /><code>function kxdrawbuttons() {</code><br /><code>&nbsp; var kxbuttons = &lt;style&gt;.kx-buttons {</code><br /><code>&nbsp; &nbsp; position:relative;</code><br /><code>&nbsp; }</code><br /><code>&nbsp; .kx-buttons span {</code><br /><code>&nbsp; &nbsp; cursor:pointer;</code><br /><code>&nbsp; }</code><br /><code>&nbsp; .kx-icon svg {</code><br /><code>&nbsp; &nbsp; &nbsp; height:22px;</code><br /><code>&nbsp; &nbsp; &nbsp; width:22px;</code><br /><code>&nbsp; }</code><br /><code>&nbsp; .kx-love-label svg {</code><br /><code>&nbsp; &nbsp; fill:#cd4343;</code><br /><code>&nbsp; }</code><br /><code>&nbsp; .kx-like-label svg {</code><br /><code>&nbsp; &nbsp; fill:#4d9d4d;</code><br /><code>&nbsp; }</code><br /><code>&nbsp; .kx-dislike-label svg {</code><br /><code>&nbsp; &nbsp; fill:#564e4e;</code><br /><code>&nbsp; }</code><br /><code>&nbsp; .kx-value {</code><br /><code>&nbsp; &nbsp; margin-right:8px;</code><br /><code>&nbsp; &nbsp; display:inline-block;</code><br /><code>&nbsp; &nbsp; position:relative;</code><br /><code>&nbsp; &nbsp; top:2px;</code><br /><code>&nbsp; &nbsp; line-height:1;</code><br /><code>&nbsp; }</code><br /><code>&nbsp; &lt;/style&gt;</code><br /><code>&nbsp; &lt;div class='kx-buttons'&gt;</code><br /><code>&nbsp; &nbsp; &lt;span class='kx-icon kx-love-label' id='kxll' title='Love This'&gt;&lt;svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor"&gt;</code><br /><code>&nbsp; &lt;path fill-rule="evenodd" d="M3.172 5.172a4 4 0 015.656 0L10 6.343l1.172-1.171a4 4 0 115.656 5.656L10 17.657l-6.828-6.829a4 4 0 010-5.656z" clip-rule="evenodd" /&gt;</code><br /><code>&lt;/svg&gt;&lt;/span&gt;</code><br /><code>&nbsp; &nbsp; &lt;span class='kx-love-value kx-value' id='kxlv'&gt;0&lt;/span&gt;</code><br /><code>&nbsp; &nbsp; &lt;span class='kx-icon kx-like-label' id='kxlil' title='Like'&gt;&lt;svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor"&gt;</code><br /><code>&nbsp; &lt;path d="M2 10.5a1.5 1.5 0 113 0v6a1.5 1.5 0 01-3 0v-6zM6 10.333v5.43a2 2 0 001.106 1.79l.05.025A4 4 0 008.943 18h5.416a2 2 0 001.962-1.608l1.2-6A2 2 0 0015.56 8H12V4a2 2 0 00-2-2 1 1 0 00-1 1v.667a4 4 0 01-.8 2.4L6.8 7.933a4 4 0 00-.8 2.4z" /&gt;&lt;/span&gt;</code><br /><code>&nbsp; &nbsp; &lt;span class='kx-like-value kx-value' id='kxliv'&gt;0&lt;/span&gt;</code><br /><code>&nbsp; &nbsp; &lt;span class='kx-icon kx-dislike-label' id='kxdl'&gt;&lt;svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor"&gt;</code><br /><code>&nbsp; &lt;path d="M18 9.5a1.5 1.5 0 11-3 0v-6a1.5 1.5 0 013 0v6zM14 9.667v-5.43a2 2 0 00-1.105-1.79l-.05-.025A4 4 0 0011.055 2H5.64a2 2 0 00-1.962 1.608l-1.2 6A2 2 0 004.44 12H8v4a2 2 0 002 2 1 1 0 001-1v-.667a4 4 0 01.8-2.4l1.4-1.866a4 4 0 00.8-2.4z" /&gt;</code><br /><code>&lt;/svg&gt;&lt;/span&gt;</code><br /><code>&nbsp; &nbsp; &lt;span class='kx-dislike-value kx-value' id='kxdv'&gt;0&lt;/span&gt;</code><br /><code>&nbsp; &lt;/div&gt;;</code><br /><code>&nbsp; document.getElementById("lovelike").innerHTML = kxbuttons;</code><br /><code>}</code><br /><code>window.onload = function() {</code><br /><code>&nbsp; kxdrawbuttons();</code></p>
<p><code>&nbsp; let kx
love = 0;</code><br /><code>&nbsp; let kxlike = 0;</code><br /><code>&nbsp; let kxdislike = 0;</code><br /><code>&nbsp; let kxclicked = false;</code></p>
<p><code>&nbsp; document.getElementById("kx
ll").onclick = function(){</code><br /><code>&nbsp; &nbsp; kxlove = 1;</code><br /><code>&nbsp; &nbsp; kxlike = 0;</code><br /><code>&nbsp; &nbsp; kxdislike = 0;</code><br /><code>&nbsp; &nbsp; if(kxclicked === false) {</code><br /><code>&nbsp; &nbsp; &nbsp; kxgetdata(kxlove,kxlike,kxdislike);</code><br /><code>&nbsp; &nbsp; }</code><br /><code>&nbsp; &nbsp; kxclicked = true;</code><br /><code>&nbsp; }</code><br /><code>&nbsp; document.getElementById("kxlv").onclick = function(){</code><br /><code>&nbsp; &nbsp; kxlove = 1;</code><br /><code>&nbsp; &nbsp; kxlike = 0;</code><br /><code>&nbsp; &nbsp; kxdislike = 0;</code><br /><code>&nbsp; &nbsp; if(kxclicked === false) {</code><br /><code>&nbsp; &nbsp; &nbsp; kxgetdata(kxlove,kxlike,kxdislike);</code><br /><code>&nbsp; &nbsp; }</code><br /><code>&nbsp; &nbsp; kxclicked = true;</code><br /><code>&nbsp; }</code><br /><code>&nbsp; document.getElementById("kxlil").onclick = function(){</code><br /><code>&nbsp; &nbsp; kxlove = 0;</code><br /><code>&nbsp; &nbsp; kxlike = 1;</code><br /><code>&nbsp; &nbsp; kxdislike = 0;</code><br /><code>&nbsp; &nbsp; if(kxclicked === false) {</code><br /><code>&nbsp; &nbsp; &nbsp; kxgetdata(kxlove,kxlike,kxdislike);</code><br /><code>&nbsp; &nbsp; }</code><br /><code>&nbsp; &nbsp; kxclicked = true;</code><br /><code>&nbsp; }</code><br /><code>&nbsp; document.getElementById("kxliv").onclick = function(){</code><br /><code>&nbsp; &nbsp; kxlove = 0;</code><br /><code>&nbsp; &nbsp; kxlike = 1;</code><br /><code>&nbsp; &nbsp; kxdislike = 0;</code><br /><code>&nbsp; &nbsp; if(kxclicked === false) {</code><br /><code>&nbsp; &nbsp; &nbsp; kxgetdata(kxlove,kxlike,kxdislike);</code><br /><code>&nbsp; &nbsp; }</code><br /><code>&nbsp; &nbsp; kxclicked = true;</code><br /><code>&nbsp; }</code><br /><code>&nbsp; document.getElementById("kxdl").onclick = function(){</code><br /><code>&nbsp; &nbsp; kxlove = 0;</code><br /><code>&nbsp; &nbsp; kxlike = 0;</code><br /><code>&nbsp; &nbsp; kxdislike = 1;</code><br /><code>&nbsp; &nbsp; if(kxclicked === false) {</code><br /><code>&nbsp; &nbsp; &nbsp; kxgetdata(kxlove,kxlike,kxdislike);</code><br /><code>&nbsp; &nbsp; }</code><br /><code>&nbsp; &nbsp; kxclicked = true;</code><br /><code>&nbsp; }</code><br /><code>&nbsp; document.getElementById("kxdv").onclick = function(){</code><br /><code>&nbsp; &nbsp; kxlove = 0;</code><br /><code>&nbsp; &nbsp; kxlike = 0;</code><br /><code>&nbsp; &nbsp; kxdislike = 1;</code><br /><code>&nbsp; &nbsp; if(kxclicked === false) {</code><br /><code>&nbsp; &nbsp; &nbsp; kxgetdata(kxlove,kxlike,kxdislike);</code><br /><code>&nbsp; &nbsp; }</code><br /><code>&nbsp; &nbsp; kxclicked = true;</code><br /><code>&nbsp; }</code></p>
<p><code>&nbsp; kx
getdata(0,0,0);</code></p>
<p><code>}</code></p>
<p><code>/</code><br /><code>function kxsendlike() {</code><br /><code>&nbsp; alert("likeclicked, send like and update value. ");</code><br /><code>}</code><br /><code>function kxsendlove() {</code><br /><code>&nbsp; alert("love clicked, send love and update value. ");</code><br /><code>}</code></p>
<p><code>function kxgetdata() {</code><br /><code>&nbsp; const data = null;</code><br /><code>&nbsp; const xhr = new XMLHttpRequest();</code><br /><code>&nbsp; xhr.withCredentials = false;</code><br /><code>&nbsp; xhr.addEventListener("readystatechange", function () {</code><br /><code>&nbsp; &nbsp; &nbsp; if (this.readyState === this.DONE) {</code><br /><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // console.log(this.responseText);</code><br /><code>&nbsp; &nbsp; &nbsp; // var data = JSON.parse(this.responseText);</code><br /><code>&nbsp; &nbsp; &nbsp; }</code><br /><code>&nbsp; });</code><br /><code>&nbsp; xhr.open("GET", "https://api.kruxor.com/callback.php?class=lovelike&amp;love=0&amp;like=0&amp;dislike=0&amp;url=test");</code><br /><code>&nbsp; xhr.send(data);</code><br /><code>&nbsp; let datajson = JSON.parse(data);</code><br /><code>}</code><br /><code>
/</code></p>
<p><br /><code>function kxgetdata(kxlove,kxlike,kxdislike) {</code><br /><code>&nbsp; &nbsp; console.log("kxlove:"+kxlove);</code><br /><code>&nbsp; &nbsp; var path = "https://api.kruxor.com/callback.php?class=lovelike&amp;love="+kxlove+"&amp;like="+kxlike+"&amp;dislike="+kxdislike+"&amp;url="+window.location.href;</code><br /><code>&nbsp; &nbsp; kxloadjson(path,"");</code><br /><code>}</code><br /><code>function kxloadjson(path, callback) {</code><br /><code>&nbsp; &nbsp; var httpRequest = new XMLHttpRequest();</code><br /><code>&nbsp; &nbsp; httpRequest.onreadystatechange = function() {</code><br /><code>&nbsp; &nbsp; &nbsp; &nbsp; if (httpRequest.readyState === 4) {</code><br /><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (httpRequest.status === 200) {</code><br /><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var data = JSON.parse(httpRequest.responseText);</code><br /><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //console.log(data);</code><br /><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let loveval = data.love;</code><br /><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; kxupdatevals(data.love, data.like, data.dislike);</code><br /><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log(loveval);</code><br /><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (callback) callback(data);</code><br /><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</code><br /><code>&nbsp; &nbsp; &nbsp; &nbsp; }</code><br /><code>&nbsp; &nbsp; };</code><br /><code>&nbsp; &nbsp; httpRequest.open('GET', path);</code><br /><code>&nbsp; &nbsp; httpRequest.send();</code><br /><code>}</code></p>
<p><code>function kx
updatevals(love, like, dislike) {</code><br /><code>&nbsp; document.getElementById("kxlv").innerHTML = love;</code><br /><code>&nbsp; document.getElementById("kxliv").innerHTML = like;</code><br /><code>&nbsp; document.getElementById("kxdv").innerHTML = dislike;</code><br /><code>}</code></p>
<h3>Result</h3>
<p><img src="https://i.imgur.com/urChNoJ.png" /></p>
<h3>Test and Working Demo</h3>
<p>Testing, and now its working... yay.</p>
<p><img src="https://i.imgur.com/ibyc1xj.gif" /></p>
<h3>Still To Add</h3>
<p>Styles, and maybe stop it at one click, rather than it sending back over and over again, when each element is clicked.&nbsp;</p>
<h3>Working</h3>
<p>Now just add this to any page and you can record love, like and dislike ratings...</p>
<p><code>&nbsp; &nbsp; &nbsp; &lt;style&gt;.kx-buttons {text-align:right;margin-bottom:10px;}&lt;/style&gt;</code><br /><code>&nbsp; &nbsp; &nbsp; &lt;div id="love_like"&gt;&amp;nbsp;&lt;/div&gt;&lt;script src="https://api.kruxor.com/js/lovelike.js"&gt;&lt;/script&gt;</code></p>

View Statistics
This Week
180
This Month
604
This Year
402

No Items Found.

Add Comment
Type in a Nick Name here
 
Other Items in API and Javascript
Search Articles
Search Articles by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

You could also follow me on twitter. I have a couple of youtube channels if you want to see some video related content. RuneScape 3, Minecraft and also a coding channel here Web Dev.

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote
1. Show your work to the world instead of keeping in your head💆. 2. Do the work consistently👌 3. Respect your work🥰 4. Don't postpone your work 5. Make mistakes 🔥🔥🔥
Unknown
Latest News
## 🚀 AI Giants Hit Bullseye: Anthropic & OpenAI Achieve Product-Market Fit Anthropic and OpenAI have reached a significant milestone, finding product-market fit with their AI technologies, which means their products effectively meet the needs of their customers, driving growth and adoption. This achievement showcases the practical value of their innovations, enabling businesses and individuals to leverage AI for enhanced productivity and efficiency. With this alignment of product and market needs, these companies are poised to transform industries and shape the future of technology.