-
Notifications
You must be signed in to change notification settings - Fork 1
Connected deadline text to be dynamic google doc #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,44 @@ | ||
//DO NOT CHANGE DELIMITERs | ||
const DELIMITER_BEG = | ||
'DO NOT DELETE THIS TEXT AND INCLUDE A SPACE AFTER COLON: '; | ||
// 2 Ending because for some reason fetching from google doc has to | ||
const DELIMITER_END1 = '</span>'; | ||
const DELIMITER_END2 = '"'; | ||
|
||
const deadlineElements = document.querySelectorAll('[data-deadline]'); | ||
|
||
fetch( | ||
//public view only url | ||
//trickfirerobotics@gmail.com | ||
'https://docs.google.com/document/d/1tRysVWzUv-sKNg6lWe7n-CvKLZU0HNW3SZiIs19d09Q/edit?usp=sharing' | ||
) | ||
.then(res => { | ||
//check to make sure API works | ||
if (!res.ok) { | ||
throw new error('DEADLINE TEXT API NOT WORKING'); | ||
} | ||
return res.text(); | ||
}) | ||
.then(text => { | ||
let indexBeg = text.indexOf(DELIMITER_BEG) + DELIMITER_BEG.length; | ||
let indexEnd = Math.min( | ||
text.indexOf(DELIMITER_END1, indexBeg), | ||
text.indexOf(DELIMITER_END2, indexBeg) | ||
); | ||
//Catches if the DELIMITER isn't found | ||
if (indexBeg == -1 + DELIMITER_BEG.length || indexEnd == -1) { | ||
throw new Error('DELIMITER WAS NOT FOUND'); | ||
} | ||
|
||
const deadlineText = `Deadline: ${text.substring(indexBeg, indexEnd)}`; | ||
//safety check to make sure it didn't go over | ||
if (deadlineText.length > 100) { | ||
throw new Error('TEXT WAS OVER 100 CHARS'); | ||
} | ||
deadlineElements.forEach(ele => { | ||
ele.innerText = deadlineText; | ||
}); | ||
}) | ||
.catch(error => { | ||
console.error(error); | ||
}); |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to make things clear, the ending index will be at either
</span>
or at"
on the Google Doc, whichever comes first?Besides that, all is good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes because there is a weird thing that happens (i don't know why) but fetching the google doc has two potential results it can pull where one has after the text it ends with
</span>
or the other with"
. That is why I added a couple of safety checks to make sure it doesn't mess up. I tried using google's own API to fetch the data making it more consistent and clean but it took 2 seconds to fetch so I opted to use this method instead