-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
61 lines (43 loc) · 2.1 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// we want to scan through the elements on a webpage and search for keywords like "instructions",
//"directions" or "ingredients"
//If those keywords are found, we will use const ingredientsWord = document.documentElement.innerText.indexOf('ingredients');
//ingredientsWord.scrollIntoView({behavior: "smooth"})
//how can I "capture" the html text of any website that I visit
//if the words "instructions" "directions" "ingredients" exist we will auto scroll to those areas
let commonIDs = ['recipe', 'ingredients', 'recipe-block_1-0', 'itr-ingredients', 'recipe-body']
let commonClasses = ['recipe', 'Recipe', 'recipe-ingredients', 'Recipe_ingredientName', 'mv-create-ingredients', 'ingredients', 'tasty-recipes-ingredients', 'itr-ingredients']
function keywordChecker() {
for (let i = 0; i < commonIDs.length; i++) {
if (document.body.contains(document.getElementById(commonIDs[i]))) {
let hashtag = `#${commonIDs[i]}`;
document.body.querySelector(hashtag).scrollIntoView({
behavior: 'smooth'
});
return;
}
}
for (let i = 0; i < commonClasses.length; i++) {
if (document.body.contains(document.getElementsByClassName(commonClasses[i]))) {
let classTag = `.${commonClasses[i]}`;
document.body.querySelector(classTag).scrollIntoView({
behavior: 'smooth'
});
return;
}
}
if (document.body.textContent.includes("Ingredients")) document.body.scrollTo(0, 950);
}
keywordChecker()
// if (document.body.textContent.includes("Directions")) {
// document.body.innerText.indexOf('Directions').scrollIntoView({behavior: "smooth"})
// }
// if (document.body.textContent.includes("Ingredients")) {
// document.body.innerText.indexOf('Ingredients').scrollIntoView({behavior: "smooth"})
// }
//examples below of how to possibly scroll the element into view once we are able to target
//text that indicates that the recipe is there
// const element = document.getElementById("box");
// element.scrollIntoView();
// element.scrollIntoView(false);
// element.scrollIntoView({block: "end"});
// element.scrollIntoView({behavior: "smooth", block: "end", inline: "nearest"});