PHP Classes

File: index.js

Recommend this page to a friend!
  Classes of Johnson Omotosho   PHP Generate Link Previewer   index.js   Download  
File: index.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: PHP Generate Link Previewer
Get preview images and descriptions from a page
Author: By
Last change:
Date: 2 years ago
Size: 1,052 bytes
 

Contents

Class file image Download
var post = document.querySelector("#post") var textarea = post.querySelector("#postvalue") var preview = { img : post.querySelector("img"), title : post.querySelector("h3"), desc : post.querySelector("p"), link : post.querySelector("small > a") } textarea.onblur = function() { previewLink(new FormData(post)) } async function previewLink(content) { var previewContainer = post.querySelector(".has-link-preview") var previewContent = await fetch('link.php',{ body : content, method : "POST" }).then((res) => res.json()) .finally((res) => { console.log("loading complete") }); if(previewContent.res) { previewContainer.style.display = "flex" preview.title.textContent = previewContent.title preview.desc.textContent = previewContent.desc.substr(0,100) + "..." preview.link.textContent = previewContent.link preview.link.href = previewContent.link preview.img.src = previewContent.img }else { previewContainer.style.display = "none" } console.log(previewContent) }