-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update to use Chromium * Log js to client log. Add readme * Add Open In Default Browser support
- Loading branch information
Showing
3 changed files
with
106 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |