-
Notifications
You must be signed in to change notification settings - Fork 1
/
code.js
188 lines (163 loc) · 8.34 KB
/
code.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// ==UserScript==
// @name AutoMS-Rewards
// @version 3.6
// @description This lets you search random words or sentences on Bing. It adds a circular Orange icon on Microsoft rewards section. You can choose the number of searches & source of the words/sentences (Either predefined or random from English dictionary), and the code will open search tabs. After 15 seconds, all tabs will be closed automatically. This script is originally made by Potaper & I added some more features like searching random words from English dictionary & change number of searches.
// @author Potaper & saitamasahil
// @match https://www.bing.com/*
// @updateURL https://github.com/saitamasahil/AutoMS-Rewards/raw/main/code.js
// @downloadURL https://github.com/saitamasahil/AutoMS-Rewards/raw/main/code.js
// @license GPL-3.0 license
// ==/UserScript==
(function () {
'use strict';
// Create an element to represent the circle icon
const icon = document.createElement('div');
icon.style.position = 'fixed';
icon.style.top = '90px';
icon.style.left = '20px';
icon.style.width = '30px';
icon.style.height = '30px';
icon.style.borderRadius = '50%'; // Make it a circle
icon.style.backgroundColor = 'orange'; // Change the color
icon.style.cursor = 'pointer';
icon.title = 'Click here to initiate a Bing random words or sentences search';
// Create an element to represent the container for the other options
const container = document.createElement('div');
container.style.position = 'fixed';
container.style.top = '130px';
container.style.left = '20px';
container.style.width = '250px';
container.style.height = '130px';
container.style.backgroundColor = 'lightcoral';
container.style.display = 'none'; // Hide the container by default
// Create an element to represent the search button
const searchButton = document.createElement('button');
searchButton.textContent = '🔎 Click here to search';
searchButton.style.margin = '6px';
searchButton.title = 'Click this button to start the search';
// Create an element to represent the toggle buttons container
const toggleButtonsContainer = document.createElement('div');
toggleButtonsContainer.style.display = 'flex';
toggleButtonsContainer.style.justifyContent = 'space-between';
toggleButtonsContainer.style.margin = '6px';
// Create an element to represent the toggle button for random words
const toggleWordsButton = document.createElement('button');
toggleWordsButton.textContent = '📚 Random Words';
toggleWordsButton.title = 'Click this button to perform a search with random words from the English dictionary';
toggleWordsButton.style.backgroundColor = 'white'; // Show white color by default
toggleWordsButton.style.flex = '1';
// Create an element to represent the toggle button for random sentences
const toggleSentencesButton = document.createElement('button');
toggleSentencesButton.textContent = '✒️ Random Sentences';
toggleSentencesButton.title = 'Click this button to perform a search with random sentences from an API';
toggleSentencesButton.style.backgroundColor = 'white'; // Show white color by default
toggleSentencesButton.style.flex = '1';
// Create variables to store the toggle states
let useRandomWords = false;
let useRandomSentences = false;
// Create an element to represent the dropdown button
const dropdown = document.createElement('select');
dropdown.title = 'Select the number of searches you want to perform';
// Add options to the dropdown button
const options = [40, 35, 30, 25, 20, 15, 10, 5];
for (let i = 0; i < options.length; i++) {
const option = document.createElement('option');
option.value = options[i];
option.text = options[i];
dropdown.appendChild(option);
}
// Define the list of predefined words
const predefinedWords = [
'car', 'cat', 'bus', 'dog', 'book', 'tree', 'cake', 'fish', 'star', 'moon',
'pen', 'hat', 'cup', 'box', 'ball', 'bird', 'rock', 'rose', 'soap', 'coin',
'key', 'map', 'pie', 'tea', 'toy', 'cow', 'egg', 'ice', 'sun', 'sky',
'bed', 'bag', 'jar', 'net', 'web', 'art', 'arm', 'eye', 'ear', 'leg',
];
// Define a function to get random words from the English dictionary
async function getRandomWords(count) {
try {
const response = await fetch(`https://random-word-api.herokuapp.com/word?number=${count}`);
const words = await response.json();
return words;
} catch (error) {
console.error('Error fetching random words:', error);
return [];
}
}
// Define a function to get random sentences from an API
async function getRandomSentences(count) {
const sentences = [];
for (let i = 0; i < count; i++) {
try {
const response = await fetch(`https://api.quotable.io/random?minLength=5&maxLength=50`);
const sentence = await response.json();
sentences.push(sentence.content);
} catch (error) {
console.error('Error fetching random sentences:', error);
}
}
return sentences;
}
// Define a function to sleep for a given amount of milliseconds
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// Search for random words or sentences when the search button is clicked
searchButton.addEventListener('click', async function () {
const pages = [];
// Get the selected number of searches from the dropdown button
const limit = parseInt(dropdown.value);
let wordsOrSentences;
if (useRandomWords) {
// Use random words from the English dictionary
wordsOrSentences = await getRandomWords(limit);
} else if (useRandomSentences) {
// Use random sentences from the API
wordsOrSentences = await getRandomSentences(limit);
} else {
// Use predefined words
wordsOrSentences = predefinedWords.slice(0, limit);
}
for (let i = 0; i < limit; i++) {
const wordOrSentence = wordsOrSentences[i] || 'fallback'; // Use a fallback word in case of error
const page = window.open(`https://bing.com/search?q=${encodeURIComponent(wordOrSentence)}`);
pages.push(page);
// Introduce a delay of 5-7 seconds between opening each tab
await sleep(5000 + Math.random() * 2000);
}
// Close all search pages after 15 seconds
setTimeout(function () {
for (let i = 0; i < pages.length; i++) {
const page = pages[i];
page.close();
}
}, 15000);
});
// Toggle the color and the state of the toggle button for random words when clicked
toggleWordsButton.addEventListener('click', function () {
useRandomWords = !useRandomWords;
useRandomSentences = false;
toggleWordsButton.style.backgroundColor = useRandomWords ? 'pink' : 'white'; // Toggle colors
toggleSentencesButton.style.backgroundColor = 'white'; // Reset sentences button color
});
// Toggle the color and the state of the toggle button for random sentences when clicked
toggleSentencesButton.addEventListener('click', function () {
useRandomSentences = !useRandomSentences;
useRandomWords = false;
toggleSentencesButton.style.backgroundColor = useRandomSentences ? 'pink' : 'white'; // Toggle colors
toggleWordsButton.style.backgroundColor = 'white'; // Reset words button color
});
// Toggle the visibility of the container when the icon is clicked
icon.addEventListener('click', function () {
container.style.display = container.style.display === 'none' ? 'block' : 'none';
});
// Append the icon and the container to the document body
document.body.appendChild(icon);
document.body.appendChild(container);
// Append the search button, the toggle buttons container, and the dropdown to the container
container.appendChild(searchButton);
toggleButtonsContainer.appendChild(toggleWordsButton);
toggleButtonsContainer.appendChild(toggleSentencesButton);
container.appendChild(toggleButtonsContainer);
container.appendChild(dropdown);
})();