Skip to content

Commit

Permalink
added features
Browse files Browse the repository at this point in the history
  • Loading branch information
mcspidey95 committed Oct 11, 2024
1 parent cd9041e commit 483befb
Show file tree
Hide file tree
Showing 10 changed files with 284 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ test.html
*.dll
*.conf
*.properties
*.bat
NOTICE.txt
browser_usage.txt
status.txt
133 changes: 120 additions & 13 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ let searchValue = '';
let isSidebarOpen = false;
let count = 0;
let splitCount = 0;
let getSuggestions = true;
let remainingText = '';
let historyCounter = 0;
let timeout;

document.addEventListener('DOMContentLoaded', () => {

Expand Down Expand Up @@ -45,6 +49,9 @@ document.addEventListener('DOMContentLoaded', () => {
const link3 = document.getElementById('mom');
const link4 = document.getElementById('dad');

let searchHistory = JSON.parse(localStorage.getItem('searchHistory')) || [];
historyCounter = searchHistory.length;

let themes = [
{
name: 'sunset',
Expand Down Expand Up @@ -994,8 +1001,6 @@ document.addEventListener('DOMContentLoaded', () => {
let message = '';
searchValue = '';

setTimeout(1000);

if(flag) {
while(exitStatus != '1') {
const getStatus = await fetch('./scripts/scriptStatus.txt');
Expand All @@ -1019,23 +1024,83 @@ document.addEventListener('DOMContentLoaded', () => {





let tempFlag = true;
let tempSearch = '';
document.addEventListener('keydown', (e) => {

if(e.key === '/'){
e.preventDefault();
}

if(e.key === 'Tab'){
e.preventDefault();
searchValue += remainingText;
updateSearch(e);
}

if(e.key === 'ArrowUp'){
e.preventDefault();
if(tempFlag){
tempFlag = false;
tempSearch = searchValue;
}

if(historyCounter > 0) {
historyCounter--;
searchValue = searchHistory[historyCounter];
}
updateSearch(e);
}

if(e.key === 'ArrowDown'){
e.preventDefault();
if(historyCounter == searchHistory.length-1) {
tempFlag = true;
searchValue = tempSearch;
}

if(historyCounter < searchHistory.length-1) {
historyCounter++;
searchValue = searchHistory[historyCounter];
}
updateSearch(e);
}

if (e.key === 'Enter' && !isSidebarOpen) {
e.preventDefault();
if (searchValue.includes('https://')) {

if(searchHistory.length >= 69)
{
searchHistory.shift();
}
if(searchValue != "")
{
searchHistory.push(searchValue);
historyCounter = searchHistory.length;
localStorage.setItem('searchHistory', JSON.stringify(searchHistory));
}

if(searchValue == ""){
showNotification("Type something re", 2000);
} else if (searchValue.includes('https://')) {
window.location.href = searchValue;
} else if (searchValue.includes('.') && !searchValue.includes(' .') && !searchValue.includes('. ')) {
} else if (searchValue.includes('.') && !searchValue.includes(' .') && !searchValue.includes('. ') && !searchValue.includes(' ')) {
window.location.href = 'https://' + searchValue;
} else if(searchValue === '/shizuku') {
setTimeout(500);
executeScript('/scripts', './scripts/shizuku/shizuku.vbs', true);
searchValue = '';
setTimeout(() => {
executeScript('/scripts', './scripts/shizuku/shizuku.vbs', true);
}, 500);
} else if(searchValue === '/pair'){
searchValue = '';
setTimeout(() => {
executeScript('/scripts', './scripts/shizuku/pair.vbs', true);
}, 500);
} else if(searchValue === '/connect'){
searchValue = '';
setTimeout(() => {
executeScript('/scripts', './scripts/shizuku/connect.vbs', true);
}, 500);
} else if(searchValue.startsWith('/cmd')) {
let command = 'cmd';

Expand All @@ -1044,10 +1109,12 @@ document.addEventListener('DOMContentLoaded', () => {
}

fetch(`/cmd?command=${command}`)
setTimeout(500);
executeScript('/scripts', './scripts/cmd.vbs', false);
setTimeout(500);
location.reload();
setTimeout(() => {
executeScript('/scripts', './scripts/cmd.vbs', false);
setTimeout(() => {
location.reload();
}, 500);
}, 500);
} else if(searchValue === '/sort') {
executeScript('/scripts', './scripts/sortDownloads/sort.vbs', true);
} else if(searchValue === '/autosort-off') {
Expand All @@ -1063,10 +1130,15 @@ document.addEventListener('DOMContentLoaded', () => {
} else if(searchValue === '/reload') {
executeScript('/scripts', './scripts/reload.vbs', false);
} else if(searchValue === '/clean') {
executeScript('/scripts', './scripts/cleaning/clear.vbs', true);
searchValue = '';
setTimeout(() => {
executeScript('/scripts', './scripts/cleaning/clear.vbs', true);
}, 500);
} else if(document.getElementById('quick_search').innerHTML === ' youtube 📺'){
searchValue.replace('+', '%2b');
window.location.href = 'https://www.youtube.com/results?search_query=' + searchValue.split(' ').join('+');
} else {
searchValue = searchValue.replace(/\+/g, '%2b');
window.location.href = engineUrl + searchValue.split(' ').join('+');
}
} else if (getComputedStyle(search).getPropertyValue('--highlight') === color3 && e.key === 'Backspace' && !isSidebarOpen) {
Expand All @@ -1081,6 +1153,7 @@ document.addEventListener('DOMContentLoaded', () => {
search.style.setProperty('--highlight', color3);
search2.style.setProperty('--highlight', color3);
searchLength = searchValue.length;
updateSearch(e);
} else if (e.ctrlKey && e.key === 'c' && getComputedStyle(search).getPropertyValue('--highlight') === color3 && !isSidebarOpen){
e.preventDefault();
navigator.clipboard.writeText(searchValue);
Expand Down Expand Up @@ -1117,7 +1190,21 @@ document.addEventListener('DOMContentLoaded', () => {
}
}

if(splitCount != 0 || getComputedStyle(search).getPropertyValue('--highlight') === color3){
getSuggestions = false;
search.innerHTML = searchValue;
}
else getSuggestions = true;

updateSearch(e);

clearTimeout(timeout);

timeout = setTimeout(() => {
if(getSuggestions && !searchValue.startsWith('/')){
autocomplete(getSuggestions);
}
}, 500);
});

document.addEventListener('click', (e) => {
Expand Down Expand Up @@ -1161,6 +1248,24 @@ document.addEventListener('DOMContentLoaded', () => {
}
});

//function searchHistory(searchQuery) {
//searchHistory.push(searchQuery);
//localStorage.setItem('searchHistory', JSON.stringify(searchHistory));
//}

async function autocomplete() {
if (searchValue.length) {
await fetch(`/search?q=${encodeURIComponent(searchValue)}`)
.then(response => response.json())
.then(data => {
let suggestion = data[0] ? data[0].phrase : '';
remainingText = suggestion.substring(searchValue.length);

search.innerHTML = `<span style="opacity: 1;">${searchValue}</span><span style="opacity: 0.5;">${remainingText}</span>`;
});
}
}

function updateSearch(e) {
if(searchValue.length <= 52 && !e.ctrlKey)
{
Expand All @@ -1170,10 +1275,12 @@ document.addEventListener('DOMContentLoaded', () => {
if(search.innerHTML.length < 52){
search.innerHTML = searchValue.slice(0, searchValue.length - splitCount);
search2.innerHTML = searchValue.slice(searchValue.length - splitCount).slice(0, 52 - search.innerHTML.length);
getSuggestions = false;
}
else{
search.innerHTML = searchValue.slice(0, searchValue.length - splitCount).slice(-52);
search2.innerHTML = searchValue.slice(searchValue.length - splitCount).slice(0, 52 - search.innerHTML.length);
getSuggestions = false;
}
}
}
Expand Down
62 changes: 62 additions & 0 deletions scripts/shizuku/connect.vbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
Option Explicit
Dim fso, shell, outputFile, devicesExec, devicesOutput, deviceLines, lastLine, i

Set shell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")

shell.CurrentDirectory = "./scripts/shizuku"

Set outputFile = fso.CreateTextFile("../scriptStatus.txt", True)
outputFile.WriteLine("Searching for Device...")
outputFile.WriteLine("0")
outputFile.Close

shell.Exec("cmd /c adb tcpip 5555")
WScript.Sleep 5000

Set outputFile = fso.CreateTextFile("../scriptStatus.txt", True)
outputFile.WriteLine("Keep Waiting...")
outputFile.WriteLine("0")
outputFile.Close

WScript.Sleep 5000

' Run the adb devices command and capture the output
Set devicesExec = shell.Exec("cmd /c adb devices")
Do While devicesExec.Status = 0
WScript.Sleep 100
Loop
devicesOutput = devicesExec.StdOut.ReadAll()

deviceLines = Split(devicesOutput, vbCrLf)

' Get the last non-empty line of the output
lastLine = ""
For i = UBound(deviceLines) To 0 Step -1
If Trim(deviceLines(i)) <> "" Then
lastLine = deviceLines(i)
Exit For
End If
Next

Set outputFile = fso.CreateTextFile("../scriptStatus.txt", True)

If LCase(Left(lastLine, 3)) = "adb" And _
LCase(Right(lastLine, 6)) = "device" Then
outputFile.WriteLine("Connected successfully")
outputFile.WriteLine("1")
shell.Run "scrcpy-noconsole.vbs"
Else
outputFile.WriteLine("Please Pair Device")
outputFile.WriteLine("1")
End If

outputFile.Close

WScript.Sleep 500
fso.DeleteFile "../scriptStatus.txt", True

Set fso = Nothing
Set shell = Nothing
Set outputFile = Nothing
Set devicesExec = Nothing
Binary file added scripts/shizuku/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions scripts/shizuku/pair.vbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Option Explicit
Dim fso, shell, outputFile, devicesExec, devicesOutput, deviceLines, lastLine, i

Set shell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")

shell.CurrentDirectory = "./scripts/shizuku"

Set outputFile = fso.CreateTextFile("../scriptStatus.txt", True)
outputFile.WriteLine("Searching for Device...")
outputFile.WriteLine("0")
outputFile.Close

' Run the adb devices command and capture the output
Set devicesExec = shell.Exec("cmd /c adb devices")
Do While devicesExec.Status = 0
WScript.Sleep 100
Loop
devicesOutput = devicesExec.StdOut.ReadAll()

deviceLines = Split(devicesOutput, vbCrLf)

' Get the last non-empty line of the output
lastLine = ""
For i = UBound(deviceLines) To 0 Step -1
If Trim(deviceLines(i)) <> "" Then
lastLine = deviceLines(i)
Exit For
End If
Next

Set outputFile = fso.CreateTextFile("../scriptStatus.txt", True)

If LCase(Left(lastLine, 3)) = "adb" And _
LCase(Right(lastLine, 6)) = "device" Then
outputFile.WriteLine("Paired successfully")
outputFile.WriteLine("1")
Else
outputFile.WriteLine("Device Not Found")
outputFile.WriteLine("1")
End If

outputFile.Close

shell.Exec("cmd /c adb tcpip 5555")

WScript.Sleep 500
fso.DeleteFile "../scriptStatus.txt", True
7 changes: 7 additions & 0 deletions scripts/shizuku/scrcpy-noconsole.vbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
strCommand = "cmd /c scrcpy.exe"

For Each Arg In WScript.Arguments
strCommand = strCommand & " """ & replace(Arg, """", """""""""") & """"
Next

CreateObject("Wscript.Shell").Run strCommand, 0, false
Binary file added scripts/shizuku/scrcpy-server
Binary file not shown.
9 changes: 9 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ app.get('/auto-sort', (req) => {
fs.writeFile('./scripts/sortDownloads/sort.txt', toggle, (err) => {})
});

app.get('/search', async (req, res) => {
let input = req.query.q;

const response = await fetch(`https://duckduckgo.com/ac/?q=${encodeURIComponent(input)}`);
const data = await response.json();

res.json(data);
});


app.listen(port, () => {
console.log(`Server running at http://localhost:${port}/`);
Expand Down
Loading

0 comments on commit 483befb

Please sign in to comment.