From 1210af1d57440cc6744c4224d2337a2c2a8e52e4 Mon Sep 17 00:00:00 2001 From: Matt Calsada Date: Thu, 25 Mar 2021 14:54:06 -0400 Subject: [PATCH] Add Chromium Support (#1) * Update to use Chromium * Log js to client log. Add readme * Add Open In Default Browser support --- Config.xml | 4 +- InternetArchiveSearch.lua | 112 +++++++++++++++++++++++++++++++------- Readme.md | 13 +++++ 3 files changed, 106 insertions(+), 23 deletions(-) create mode 100644 Readme.md diff --git a/Config.xml b/Config.xml index 4a0ae99..efeb156 100644 --- a/Config.xml +++ b/Config.xml @@ -1,8 +1,8 @@ Internet Archive Search - Simmons College Library - 1.1 + Atlas Systems and Simmons College Library + 2.0.0 true Performs a search of internet archive for a loans' LoanTitle. diff --git a/InternetArchiveSearch.lua b/InternetArchiveSearch.lua index fc638b9..5e5cdea 100644 --- a/InternetArchiveSearch.lua +++ b/InternetArchiveSearch.lua @@ -1,31 +1,56 @@ -- About InternetArchiveSearch.lua -- --- Developed by Simmons College Library +-- Developed by Atlas Systems and Simmons College Library + +-- Version 2.0.0, March 2021, Atlas Systems, Inc. +-- * Converted addon to use Chromium-based browsers -- --- Version 1.1, April 2010 +-- Version 1.1, April 2010, Simmons College Library -- -- InternetArchiveSearch.lua does search of Internet Archive for the LoanTitle for loans. -- autoSearch (boolean) determines whether the search is performed automatically when a request is opened or not. --- --- "query" is the text box name on archive.org + +---- +---- Initial setup to open a new process (default browser) +-- Load the .NET System Assembly +luanet.load_assembly("System"); +Types = {}; +--Store the Process type to instantiate a new process later +Types["Process"] = luanet.import_type("System.Diagnostics.Process"); +---- + local autoSearch = GetSetting("AutoSearch"); local interfaceMngr = nil; -local browser = nil; +local addonForm = {}; function Init() if GetFieldValue("Transaction", "RequestType") == "Loan" then + interfaceMngr = GetInterfaceManager(); - - -- Create browser - browser = interfaceMngr:CreateBrowser("Internet Archive Search", "Internet Archive Search", "Script"); - - -- Create buttons - browser:CreateButton("Search", GetClientImage("Search32"), "Search", "Internet Archive"); - - browser:Show(); - + + -- Create a form + addonForm.Form = interfaceMngr:CreateForm("Internet Archive Search", "Internet Archive Search"); + + -- Add a browser + addonForm.Browser = addonForm.Form:CreateBrowser("Internet Archive Search", "Internet Archive Search", "Internet Archive", "Chromium"); + + -- Hide the text label + addonForm.Browser.TextVisible = false; + addonForm.Browser:CollapseTextPlaceholder(); + + -- Since we didn't create a ribbon explicitly before creating our browser, it will have created one using the name we passed the CreateBrowser method. + -- We can retrieve that one and add our buttons to it. + addonForm.RibbonPage = addonForm.Form:GetRibbonPage("Internet Archive"); + + -- Create the search button + addonForm.RibbonPage:CreateButton("Search", GetClientImage("Search32"), "Search", "Internet Archive"); + addonForm.RibbonPage:CreateButton("Open New Browser", GetClientImage("Web32"), "OpenInDefaultBrowser", "Utility"); + + -- After we add all of our buttons and form elements, we can show the form. + addonForm.Form:Show(); + if autoSearch then Search(); end @@ -33,14 +58,59 @@ function Init() end function Search() - browser:RegisterPageHandler("formExists", "searchform","SearchFormLoaded", false); - browser:Navigate("http://archive.org"); + addonForm.Browser:RegisterPageHandler("formExists", "searchform","SearchFormLoaded", false); + addonForm.Browser:Navigate("http://archive.org"); end -function SearchFormLoaded() - if GetFieldValue("Transaction", "RequestType") == "Loan" then - browser:SetFormValue("searchform", "search", GetFieldValue("Transaction", "LoanTitle")); - end - browser:ClickObject("gobutton"); +function SearchFormLoaded() + if GetFieldValue("Transaction", "RequestType") == "Loan" then + SearchInternetArchives(addonForm.Browser, "searchform", "search", GetFieldValue("Transaction", "LoanTitle")); + end +end + +function SearchInternetArchives(browser, formName, inputName, value) + if browser then + --Script to execute + local searchInternetArchives = [[ + (function(formName, inputName, value) { + //Write to the client log. + //Use ES6 Template Strings to concatenate - using back-ticks: https://developers.google.com/web/updates/2015/01/ES6-Template-Strings + atlasAddonAsync.executeAddonFunction("LogDebug", `Performing Internet Archives Search: ${value}` ); + + let form = document.forms[formName]; + if (!(form)) { + atlasAddonAsync.executeAddonFunction("LogDebug", `Unable to find form: ${formName}` ); + return; + } + + let inputElement = form.elements[inputName]; + if (!(inputElement)) { + atlasAddonAsync.executeAddonFunction("LogDebug", `Unable to find form input: ${inputName}` ); + return; + } + inputElement.value = value; + + //Internet Archive masks form submit with a hidden element with name "submit" + //Instead, look for a the button and click it + if (form.getElementsByTagName("button").length == 1) { + form.getElementsByTagName("button")[0].click(); + } + }) + ]]; + + browser:ExecuteScript(searchInternetArchives, { formName, inputName, value }); + end end +function OpenInDefaultBrowser() + local currentUrl = addonForm.Browser.Address; + + if (currentUrl and currentUrl ~= "")then + LogDebug("Opening Browser URL in default browser: " .. currentUrl); + + local process = Types["Process"](); + process.StartInfo.FileName = currentUrl; + process.StartInfo.UseShellExecute = true; + process:Start(); + end +end \ No newline at end of file diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..32150dc --- /dev/null +++ b/Readme.md @@ -0,0 +1,13 @@ +# ILLiad Internet Archive Search Addon + +Performs a search of internet archive + +_The Internet Archive Search addon was originally developed and maintained by Simmons College Library._ + +## Addon Settings + +### AutoSearch + +_Default: True_ + +Defines whether the search should be automatically performed when the form opens.