Skip to content

Commit

Permalink
Update script.gs
Browse files Browse the repository at this point in the history
  • Loading branch information
WillDev12 authored Feb 19, 2023
1 parent 3ead8b5 commit d175559
Showing 1 changed file with 44 additions and 28 deletions.
72 changes: 44 additions & 28 deletions scr/open/script.gs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ function onOpen()

ui.createMenu('MLA Helper')

.addItem('Launch GUI', 'launchGUI')

.addSeparator()

.addItem('Make MLA Header', 'newHeader')

.addItem('New Quote', 'newQuote')
Expand All @@ -22,23 +26,21 @@ function onOpen()
.addSeparator()
.addItem('Book', 'newCitation'))

.addSeparator()

.addItem("Times New Romanator", "timesNew")
.addItem("Italicator", "italixer")
.addSubMenu(DocumentApp.getUi().createMenu('Fonts')
.addItem("Times New Romanator", "timesNew")
.addItem("Italicator", "italixer"))

.addToUi();

ui.alert("MLA Helper script by WillDevv12 \n\n Catch me on GitHub: https://github.com/WillDev12")
ui.alert("MLA Helper v1.0.5 script by WillDevv12 \n\n Catch me on GitHub: https://github.com/WillDev12")

}

function newQuote()
{

var text = '<!DOCTYPE html><html><head><base target="_top"><link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"><script>function CreateQuote() {var quote = document.getElementById("quote").value;var author = document.getElementById("author").value;var pagen = document.getElementById("page").value;if (author === "") {var e = "null";google.script.run.FeedbackError(e);return;} else if (quote === "") {var e = "null";google.script.run.FeedbackError(e);return;}else if (pagen === "") {var e = "null";google.script.run.FeedbackError(e);return;}google.script.run.SendQuote(quote, author, pagen);google.script.host.close();}</script></head><body><div class="w3-card" style="margin: 20px"><div class="w3-container w3-blue"><h2>New quote</h2></div><div class="w3-container w3-light-gray"><br>Quote: (Do not include a final period) <br> <input type="text" id="quote" style="width:260px" required/><br>Authors last name: <br> <input type="text" id="author" style="width:260px" required/><br>Page #: <br> <input type="text" id="page" style="width:260px" required/><br><input type="button" value="Create" onclick="CreateQuote()" style="width:100px; margin-top: 20px; margin-bottom: 20px"/></div></div></body></html>'

var form = HtmlService.createHtmlOutput(text)
var output = UrlFetchApp.fetch("https://raw.githubusercontent.com/WillDev12/MLA-Helper/main/scr/html/quote.html");
var form = HtmlService.createHtmlOutput(output.getContentText())
.setWidth(800)
.setHeight(360);

Expand All @@ -49,9 +51,8 @@ function newQuote()
function newCitation()
{

var text = '<!DOCTYPE html><html><head><base target="_top"><link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"><script>function SendCitation() {var cont = document.getElementById("contribution1").value;var afn = document.getElementById("afn").value;var amn = document.getElementById("amn").value;var aln = document.getElementById("aln").value;var asfx = document.getElementById("asfx").value;var title = document.getElementById("title").value;var pub = document.getElementById("pub").value;var city = document.getElementById("city").value;var sn = document.getElementById("sn").value;var snum = document.getElementById("snum").value;var edition = document.getElementById("edition").value;var year = document.getElementById("year").value;google.script.run.CreateCitation(cont, afn, amn, aln, asfx, title, pub, city, sn, snum, edition, year);google.script.host.close();}</script></head><body><div class="w3-card"><div class="w3-container w3-blue"><h2>Author & Contributions</h2></div><div class="w3-container w3-light-gray" style="padding: 20px"><label for="contribution1">Choose a role:</label><select name="contribution1" id="contribution1"><option value="default">Role</option><option value="Author">Author</option><option value="Translator">Translator</option></select><br>Authors first name: <br> <input type="text" id="afn" style="width:260px" required/><br>Authors middle name: <br> <input type="text" id="amn" style="width:260px" required/><br>Authors last name: <br> <input type="text" id="aln" style="width:260px" required/><br>Suffix: <br> <input type="text" id="asfx" style="width:150px" required/><br><br></div><br><div class="w3-container w3-blue"><h2>Book Info</h2></div><div class="w3-container w3-light-gray" style="padding: 20px">Title: <br> <input type="text" id="title" style="width:260px" required/><br>Publisher: <br> <input type="text" id="pub" style="width:260px" required/><br>Year: <input type="text" id="year" style="width:150px" required/><br>Publication City: <br> <input type="text" id="city" style="width:260px" required/><br>Edition: <br> <input type="text" id="edition" style="width:260px" required/><br>Series name & number: <br> <input type="text" id="sn" style="width:100px" required/><input type="text" id="snum" style="width:100px" required/><br><input type="button" value="Create" onclick="SendCitation()" style="width:100px; margin-top: 20px"/></div></body></html>'

var form = HtmlService.createHtmlOutput(text)
var output = UrlFetchApp.fetch("https://raw.githubusercontent.com/WillDev12/MLA-Helper/main/scr/html/citation.html");
var form = HtmlService.createHtmlOutput(output.getContentText())
.setWidth(800)
.setHeight(700);

Expand All @@ -68,6 +69,18 @@ function newHeader()

}

function returnedHeading(title, name, tname, came, day, month, year) {

const monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];


body.insertParagraph(0, name+"\n"+tname+"\n"+came+"\n"+day+" "+monthNames[month]+" "+ year +"\n\n");
body.insertParagraph(1, title).setAlignment(DocumentApp.HorizontalAlignment.CENTER);

}

function timesNew()
{

Expand Down Expand Up @@ -146,9 +159,10 @@ function SendQuote(quote, author, pagen)
var surroundingText = cursor.getSurroundingText();
surroundingText.appendText(str);


}

function CreateCitation(cont, afn, amn, aln, asfx, title, pub, city, sn, snum, edition, year)
function citeBook(cont, afn, amn, aln, asfx, title, pub, city, sn, snum, edition, year)
{

var product = ""
Expand Down Expand Up @@ -188,7 +202,7 @@ function CreateCitation(cont, afn, amn, aln, asfx, title, pub, city, sn, snum, e

}

if (cont === "default") {
if (cont === "role") {

} else {

Expand Down Expand Up @@ -252,19 +266,11 @@ function CreateCitation(cont, afn, amn, aln, asfx, title, pub, city, sn, snum, e

}

///////////////////////////////////////////////////////////////////////

var cursor = DocumentApp.getActiveDocument().getCursor();
var surroundingText = cursor.getSurroundingText();
surroundingText.appendText(product);
var surroundingText = cursor.getSurroundingText();
surroundingText.appendText(italix);
var surroundingText = cursor.getSurroundingText();
surroundingText.appendText(product2);
surroundingText = cursor.getSurroundingText();
surroundingText.appendText("\n " + indent1);

///////////////////////////////////////////////////////////////////////
var output = "<p>"+product+"<i>"+italix+"</i>"+product2+"<br>&emsp;"+indent1;
var form = HtmlService.createHtmlOutput(output)
.setWidth(500)
.setHeight(150);
ui.showModalDialog(form, 'Output Citation');

}

Expand All @@ -273,14 +279,24 @@ function FeedbackError(e)

if (e === "null") {

ui.alert("ERROR: One or more of your input feilds are empty.")
ui.alert("ERROR: One or more required inputs are missing.")

} else if (e === "nullselected") {

ui.alert("ERROR: You must select text before running this script.")

} else {

ui.alert(e);

}

}

//Enjoy :)
function launchGUI() {

var s = UrlFetchApp.fetch("https://raw.githubusercontent.com/WillDev12/MLA-Helper/main/scr/html/sidebar.html");
var service = HtmlService.createHtmlOutput(s.getContentText()).setTitle('MLA Helper');
DocumentApp.getUi().showSidebar(service);

}

0 comments on commit d175559

Please sign in to comment.