Javascript File
// plugin.js function GoogleSearchMePlugin(options) { let defaultOptions = { base_url: "https://www.google.com/?q=", keyword: "imnobby", container_id: "imnobby-container", display_bold: true, } options = { ...defaultOptions, ...options }; let _this = this; this.init = function() { let url = options.base_url + options.keyword; // console.log("url: " + url); let container_html = "<h1>Click To Search Me</h1>"; if (options.display_bold) { container_html += '<a href="' + url + '" target="_blank"><strong>Search In Google</strong></a>'; } else { container_html += '<a href="' + url + '" target="_blank">Search In Google</a>'; } document.getElementById(options.container_id).innerHTML = container_html; } this.doStarterTemplate = function() { const someBtn = doucment.CreateElement("button"); someBtn.SetAttribute("class", "some-class"); someBtn.innerHTML = "Some Text"; let someContainer = document.createElement("div"); someContainer.appendChild(someBtn); someBtn.addEventListener("click", function() { _this.doSomeBtnFunc(); }) } this.doSomeBtnFunc = function() { } this.init(); }
HTML and Javascript
<script src="plugin.js"></script> <div id="imnobby-container"></div> <script> // Init Script After Div var searchLink = new GoogleSearchMePlugin({ base_url: "https://www.google.com/?q=", keyword: "imnobby", container_id: "imnobby-container", }) </script>
Other Resources
Related Keywords: Developer, How-to, Solved, JS Plugin Template, Starter Template, Basic Template, Sample Code