Skip to content

Commit

Permalink
Add Chromium Support (#1)
Browse files Browse the repository at this point in the history
* Update to use Chromium

* Log js to client log. Add readme

* Add Open In Default Browser support
  • Loading branch information
mcalsada authored Mar 25, 2021
1 parent cef3e59 commit 1210af1
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 23 deletions.
4 changes: 2 additions & 2 deletions Config.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Name>Internet Archive Search</Name>
<Author>Simmons College Library</Author>
<Version>1.1</Version>
<Author>Atlas Systems and Simmons College Library</Author>
<Version>2.0.0</Version>
<Active>true</Active>
<Description>Performs a search of internet archive for a loans' LoanTitle.</Description>
<Forms>
Expand Down
112 changes: 91 additions & 21 deletions InternetArchiveSearch.lua
Original file line number Diff line number Diff line change
@@ -1,46 +1,116 @@
-- 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
end
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
13 changes: 13 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 1210af1

Please sign in to comment.