If I create a search engine and put in, for example, the Wikipedia url, only that home page will appear. How can I make it so that all the pages of a website are added to the database or that all the pages of a website appear in the search engine without having to add each one manually?
Is there any way of doing this? Because having to add each page of a website manually is impossible, even worse if it’s several websites.
I think Google uses a tracking mechanism to do this, I don’t know.
Category: javascript
Category Added in a WPeMatico Campaign
The ffmpeg output binary stream front-end uses WebSocket to accept and cannot be played
Server push nodejs
Use ws service to pass to the front end
ffmpegs = spawn('ffmpeg', [
'-f', 'gdigrab', // 这是 Windows 下用于捕获屏幕的输入格式
'-framerate', '60', // 捕获帧率
'-i', 'desktop', // 捕获桌面(即屏幕)
'-c:v', 'vp8', // 视频编码格式
'-f', 'webm', // 设置输出为 mpegts 流
'-pix_fmt', 'yuv420p',
'pipe:1', // 输出到管道
]);
Front-end rendering
let videoElement = document.getElementById('screenVideo');
let mediaSource = new MediaSource();
videoElement.src = URL.createObjectURL(mediaSource);
mediaSource.addEventListener('sourceopen', () => {
let sourceBuffer = mediaSource.addSourceBuffer('video/webm; codecs="vp8"');
let ws = new WebSocket(`ws://${ip}:3000/?device=${encodeURIComponent(selectedDevice)}`);
ws.onmessage = (event) => {
const data = new Uint8Array(event.data);
if (!sourceBuffer.updating) {
try {
sourceBuffer.appendBuffer(data);
console.log('ok')
} catch (error) {
console.error('Error appending buffer:', error);
}
} else {
console.log('SourceBuffer is busy');
}
};
ws.onerror = (error) => {
console.error('WebSocket error:', error);
};
ws.onclose = () => {
console.log('WebSocket connection closed');
};
if (mediaSource.readyState === 'open') {
videoElement.play().catch(err => {
console.error('Error attempting to play the video:', err);
});
}
}
The video keeps spinning in circles and cannot be played normally.
Unable to play normally. What’s the problem?
javascript animation not working properly
I’m making a voting system, and I want the option with the most votes rank at the top with a switching animation but I don’t know how to do so.
function updateResults() {
for (let option in votes) {
let percentage = (votes[option] / totalVotes) * 100 || 0;
document.getElementById(option.toLowerCase().replace(' ', '')).style.width = percentage + '%';
document.getElementById(`${option.toLowerCase().replace(' ', '')}-percentage`).innerText = Math.round(percentage) + '%';
}
}
please provide a simple explanation of how the switch up animation and the ranking change is applied.
I tried messing around with the animation but never got the result I wanted. I managed to get the option with the most votes to go to the top but it always ended up teleporting
GTranslate Plugin Compatibility Issue with Integrated Lazy Page Speed in WordPress
I’m experiencing a compatibility issue between the Lazy Page Speed feature integrated into my theme and the GTranslate plugin on my WordPress site. Specifically, the Lazy Page Speed optimization is altering the tag for the GTranslate plugin, which causes it to malfunction. The altered tag appears as follows:
<script data-laps-action="reorder" type="javascript/blocked" id="gt_widget_script_XXXX-js-before">
Whereas it should normally appear like this:
<script id="gt_widget_script_XXXX-js-before">
This alteration prevents the GTranslate plugin from displaying correctly, causing issues with the language switcher and flag icons on the front-end of the site. After inspecting the issue, I confirmed that disabling the Lazy Page Speed feature resolves the problem. However, I would like to keep Lazy Page Speed enabled for the rest of the site’s performance optimizations while resolving the issue with GTranslate.
I tried disabling the Lazy Page Speed feature and found that it resolved the issue with the GTranslate plugin. However, I did not want to completely disable the optimization because it is critical for improving my site’s performance. Instead, I was hoping to find a way to:
> Exclude or adjust the optimization specifically for the GTranslate plugin, so that the Lazy Page Speed optimization doesn't interfere with it.
> Ensure that the rest of the site still benefits from the performance enhancements provided by Lazy Page Speed.
I am looking for a solution that allows both Lazy Page Speed and GTranslate to work together without causing issues on the site.
Type error on graph ql mutation using knn algortihm [closed]
https://pastecode.io/s/qihwx0hu this is the knn function which I am sending request to from the back end graphql server.
https://pastecode.io/s/nct1fi4t
Above is the gql request I am sending. And below the gql error I am getting.
https://pastecode.io/s/6ia614w0.
I don’t know how to approach the issue and solve it. Please help. Thanks in advance
Serving images from device cache (web app)
I have a go / htmx stack app that is serving images from s3 with a cloudfront distribution in front. I am attempting to load images from a service worker and store them in a cache then serve them from the cache if they exist there before sending an actual network request to cloudfront. The images are requested via an img src tag via the application code. The service worker currently is successful in storing these images in the cache, but the screenshot here is confusing as it’s leading me to believe that the image is being requested from cloudfront again.
I am unable to log any response from the following service worker code. I am only pasting the “fetch” listener code of the service worker as it is the relevant code:
self.addEventListener('fetch', event => {
if (event.request.destination === 'image' && event.request.url.includes("cloudfront.net")) {
event.respondWith(
caches.match(event.request)
.then(response => {
// Return the cached image if available, otherwise fetch from network
console.log(response)
return response || fetch(event.request).then(networkResponse => {
// Cache the new image and return it
const responseClone = networkResponse.clone();
caches.open(CACHE_NAME).then((cache) => {
cache.put(event.request, responseClone);
});
return networkResponse;
});
}).catch((err) => {
// Fallback image if network fetch fails and not in cache
console.log("not in: ", err)
return;
})
);
}
});
I would expect to see (disk cache) or (memory cache) next to the images fetched by the service worker.
Javascript: which is better, conditional return or conditional block? [closed]
Suppose I have a function which returns nothing, with code that should execute only if a condition is not met. What is best from a performance/efficiency perspective:
- to begin with a conditional return statement:
function f() {
if (condition) return;
// Do something...
}
- or to use a conditional block:
function f() {
if (!condition) {
// Do something...
}
}
?
Nuxt Build Error: [vite]: Rollup failed to resolve import
I have a Nuxt app with Primevue library. Running the app in dev mode is perfectly fine. However when I try to build the app for production using npm run build. This error occurs:
Nuxt Build Error: [vite]: Rollup failed to resolve import "/Users/borisgrigorov/Dev/sgb/node_modules/@primevue/nuxt-module/dist/runtime/plugin.client" from "virtual:nuxt:/Users/borisgrigorov/Dev/sgb/.nuxt/plugins.client.mjs".
This is most likely unintended because it can break your application at runtime.
Full log stack:
Nuxt 3.14.159 with Nitro 2.10.4 4:45:12 PM
ℹ Using default Tailwind CSS file nuxt:tailwindcss 4:45:12 PM
✔ Prisma CLI is already installed. 4:45:18 PM
✔ Prisma schema file exists. 4:45:18 PM
✔ Database migrations folder exists. 4:45:18 PM
4:45:18 PM
Not migrating the database.
Generating Prisma client... 4:45:18 PM
4:45:24 PM
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
✔ Generated Prisma Client (v5.22.0) to ./node_modules/@prisma/client in 190ms
Skipped installing Prisma Studio. 4:45:24 PM
WARN Slow module @prisma/nuxt took 11873.1ms to setup. 4:45:24 PM
WARN Failed to parse static properties from plugin node_modules/@primevue/nuxt-module/dist/runtime/plugin.client. ENOENT: no such file or directory, open '/Users/borisgrigorov/Dev/sgb/node_modules/@primevue/nuxt-module/dist/runtime/plugin.client' 4:45:25 PM
at async open (node:internal/fs/promises:639:25)
at async Object.readFile (node:internal/fs/promises:1242:14)
at async annotatePlugins (node_modules/nuxt/dist/index.mjs:5592:68)
at async Object.getContents (node_modules/nuxt/dist/index.mjs:4942:27)
at async processTemplate (node_modules/nuxt/dist/index.mjs:5444:22)
at async Promise.allSettled (index 0)
at async generateApp (node_modules/nuxt/dist/index.mjs:5472:3)
at async _applyPromised (node_modules/perfect-debounce/dist/index.mjs:54:10)
WARN Failed to parse static properties from plugin node_modules/@primevue/nuxt-module/dist/runtime/plugin.client. ENOENT: no such file or directory, open '/Users/borisgrigorov/Dev/sgb/node_modules/@primevue/nuxt-module/dist/runtime/plugin.client' 4:45:25 PM
at async open (node:internal/fs/promises:639:25)
at async Object.readFile (node:internal/fs/promises:1242:14)
at async annotatePlugins (node_modules/nuxt/dist/index.mjs:5592:68)
at async Object.getContents (node_modules/nuxt/dist/index.mjs:5004:26)
at async processTemplate (node_modules/nuxt/dist/index.mjs:5444:22)
at async Promise.allSettled (index 1)
at async generateApp (node_modules/nuxt/dist/index.mjs:5472:3)
at async _applyPromised (node_modules/perfect-debounce/dist/index.mjs:54:10)
ℹ Building client... 4:45:26 PM
ℹ vite v5.4.10 building for production... 4:45:26 PM
ℹ ✓ 24 modules transformed. 4:45:26 PM
ERROR x Build failed in 217ms 4:45:26 PM
ERROR Nuxt Build Error: [vite]: Rollup failed to resolve import "/Users/borisgrigorov/Dev/sgb/node_modules/@primevue/nuxt-module/dist/runtime/plugin.client" from "virtual:nuxt:/Users/borisgrigorov/Dev/sgb/.nuxt/plugins.client.mjs". 4:45:26 PM
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
build.rollupOptions.external
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
build.rollupOptions.external
at viteWarn (node_modules/vite/dist/node/chunks/dep-BWSbWtLw.js:65589:17)
at onRollupWarning (node_modules/vite/dist/node/chunks/dep-BWSbWtLw.js:65621:5)
at onwarn (node_modules/vite/dist/node/chunks/dep-BWSbWtLw.js:65284:7)
at node_modules/rollup/dist/es/shared/node-entry.js:19470:13
at Object.logger [as onLog] (node_modules/rollup/dist/es/shared/node-entry.js:21196:9)
at ModuleLoader.handleInvalidResolvedId (node_modules/rollup/dist/es/shared/node-entry.js:20085:26)
at node_modules/rollup/dist/es/shared/node-entry.js:20043:26
I tried to add the @primevie/nuxt-module to vite.build.rollipOotions.external in nuxt.config.ts, but that didn’t help in any way.
My package.json:
{
"name": "sgb",
"private": true,
"type": "module",
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare"
},
"dependencies": {
"@nuxtjs/tailwindcss": "^6.12.1",
"@pinia/nuxt": "^0.6.0",
"@primevue/themes": "4.1.1",
"@prisma/nuxt": "^0.0.35",
"bcrypt": "^5.1.1",
"emailjs": "^4.0.3",
"iron-session": "^8.0.3",
"joi": "^17.13.3",
"nuxt": "^3.13.0",
"pinia": "^2.2.5",
"primeicons": "^7.0.0",
"primevue": "4.1.1",
"vue": "latest",
"vue-router": "latest"
},
"devDependencies": {
"@primevue/nuxt-module": "^4.1.1",
"@prisma/client": "^5.22.0",
"@types/bcrypt": "^5.0.2"
},
"overrides": {
"vue": "latest"
}
}
I would be thankful for any suggestions.
Working with too much contents of a collection in AstroJS
I have a project Archive page as below.
As you can see, I bring all the projects and perform filter, sort and pagination operations.
---
interface Props {
page?: string;
}
const { page } = Astro.props;
// Projects
const projects = (
await getCollection("projects", ({ data }) => {
return data.get.language === language && data.get.status === "publish";
})
).sort((a, b) => {
const sortOrders = b.data.get.sortOrder - a.data.get.sortOrder;
return sortOrders !== 0
? sortOrders
: Date.parse(b.data.get.publishDate) - Date.parse(a.data.get.publishDate);
});
// Get featured projects
const featuredProjects = projects.filter(
(data) => data.data.get.featured === true
);
// Find featured project
const featuredProject = featuredProjects.length ? featuredProjects[0] : null;
// Normal projects
const normalProjects = featuredProject
? projects.filter((data) => data != featuredProject)
: projects;
// Total pages
const totalPages: number = Math.ceil(
normalProjects.length / options.postsPerPage
);
// Current page
const currentPage = +page! || 1;
// Current page's projects
const currentProjects = normalProjects.slice(
(currentPage - 1) * options.postsPerPage,
currentPage * options.postsPerPage
);
---
<div></div>
What came to my mind was the possibility of slowdowns and even crashes in the long run as the number of projects increases due to excessive memory usage by these processes.
Yes, there won’t be that many projects, but I will use this structure in the future for archives like “Blog” etc. And yes, the number of blogs can be quite high.
That’s why I want to take precautions at the source before the problem even starts, and I ask, will this structure cause major problems in the future when there is a lot of archive content?
Your answer is probably yes (otherwise you would make me very happy), so:
The biggest problem here (while probably displaying 10-20 of them on a single page) is calling all of them with
getCollection.
- In this case, if I put the pagination in
getCollectionand query
the content as much as the firstperPage + 1each time, and if
that much content is returned, I should know that the next page will
also have at least 1 item. - Does this approach eliminate any performance issues that may arise?
- I’m afraid that with this approach I won’t know the value of
totalPages, so I’ll have to use<next-prev> Paginationinstead
ofNumeric Pagination, which is very bad. (Is there a preformed
way to get around this and get the total number of pages?) - With all this, without directing you: If anyone has another solution
or suggestion that is completely unique to you, I would be happy to
read them.
All things aside: I don’t know if there is a way to “get” content between 1 and 10, 11 and 20, 21 and 30 … when querying the getCollection function (see here) 😀
Before I forget: The project is SSR (running server-side).
Reactive form in angular with grouped check box panel
From a dynamic Json like below one
[
{
"label": "General",
"data": [
{
"title": "parameters.deviceInfo.name"
},
{
"title": "assetAttributes.manufacturerLabel"
}
]
},
{
"label": "Associated Device",
"data": [
{
"title": "assetAttributes.operationsLabel",
},
{
"title": "assetAttributes.adapterIpAddress",
}
]
},
{
"label": "profile.identificationTabLabel",
"data": [
{
"title": "assetAttributes.assetIdLabel"
}
]
},
{
"label": "profile.communicationTabLabel",
"data": [
{
"title": "profile.networkGroupLabel",
},
{
"title": "assetAttributes.gtwAddressLabel",
}
]
},
{
"label": "profile.locationTabLabel",
"data": [
{
"title": "assetAttributes.latitudeLabel"
},
{
"title": "assetAttributes.longitudeLabel"
}
]
},
{
"label": "profile.customersTabLabel",
"data": [
{
"title": "assetAttributes.mRidLabel"
},
{
"title": "assetAttributes.epsNameLabel"
}
]
}
]
want to create reactive form in angular with grouped check box panel with select all for each object. That means when user clicks general checkbox, all the items inside that panel should be checked. Also one select all for selecting all the panel elements in one click.
On the first load of my site, why does it redirect the the page I access with XMLHttpRequest?
In the script at the bottom I get the result from /php/get/items-sold.php and put it into the div called items-list. It’s not supposed to actually go to the page /php/get/item-sold.php, but on the FIRST load of my site it does – or it goes to the banner php file or the sidebar php file which are loaded in sidebar.js. But on subsequent loads it works entirely like it’s supposed to.
I just tried putting the code that loads it in an event listener for DOMContentLoaded, as you can see in my code below, but it fixed nothing.
What could be causing this and how can I fix it?
<!DOCTYPE HTML>
<html>
<head>
<title>Crochet Store</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link rel="stylesheet" href="/assets/css/main.css" />
</head>
<body class="is-preload">
<script>
// to eliminate Flash Of Unstyled Content
const loadingOverlay = document.createElement("div");
loadingOverlay.id = "loading-overlay";
loadingOverlay.innerHTML = "<div class='lds-ring'><div></div><div></div><div></div><div></div></div>";
document.getElementsByTagName("body")[0].prepend(loadingOverlay);
</script>
<!-- Wrapper -->
<div id="wrapper">
<!-- Main -->
<div id="main">
<div class="inner">
<!-- Header -->
<!-- sidebar.js will fill this -->
<header id="header"><p id="js-disabled-warning">You have javascript disabled... the site needs javascript to function. Please enable javascript :(</p></header>
<!-- Banner -->
<!-- sidebar.js will fill this -->
<section id="banner"></section>
<!-- Section -->
<section>
<header class="major">
<h2>Items I Sell:</h2>
</header>
<div id="items-list"></div>
</section>
</div>
</div>
<!-- sidebar.js will fill this -->
<div id="sidebar"></div>
</div>
<!-- Scripts -->
<script src="/assets/js/jquery.min.js"></script>
<script src="/assets/js/sidebar.js"></script>
<script src="/assets/js/util.js"></script>
<script src="/assets/js/main.js"></script>
<script>
function resizeBannerImg() {
const width = document.getElementById("banner-img").clientWidth;
$("banner-img").attr("height", width);
}
window.addEventListener("DOMContentLoaded", function() {
xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function() {
const response = this.responseText;
$("#items-list").html(response);
};
xmlhttp.open("GET", "/php/get/items-sold.php");
xmlhttp.send();
});
</script>
</body>
</html>
How to Build a Multilingual Voice Assistant for Web Text-to-Speech on Hover Events?
I’m working on a web project where I want to implement a voice assistant that reads out text when users hover over it. The assistant should:
- Support multiple languages based on the text content.
- Use text-to-speech APIs efficiently to ensure smooth performance.
- Be responsive and not cause delays or excessive resource usage.
What are the best practices for integrating this feature, and which text-to-speech APIs (e.g., Web Speech API, third-party options) would you recommend for optimal performance? Bonus points for tips on handling edge cases, like detecting the correct language or ensuring accessibility compliance.
What Did I Try?
“I have explored using the Web Speech API for text-to-speech functionality and was able to get basic speech output working. I also tried detecting the language of the text using a simple script and passing it to the API. However, the performance wasn’t smooth when multiple hover events occurred in quick succession.”
What am I Expecting?
“I was expecting the assistant to handle hover events seamlessly, dynamically switch between languages based on text content, and provide an instant, natural-sounding response. Additionally, I wanted to ensure the solution remains efficient without overloading the browser or causing lag.
How do i define the fib() function, which returns the next Fibonacci number after each call?
Define the fib() function, which returns the next Fibonacci number after each call.
The solution should inject only the name of the fib function into the global scope and not create additional properties of the fib function or its properties.
I need the help by using JavaScript, I’m troubling with the solution..
How do I get JavaScript code to execute in Chrome from an HTML document?
Very basically, how do I get JavaScript code to execute in my browser? I am working
through a book which asks me to embed my JS code between tags in an HTML file, like this:
<!DOCTYPE html>
<body>
<script>
console.log("Hello");
</script>
</body>
</html>
My browser will still run JS code which involves the alert() method, and a pop-up will be displayed on the screen as expected. Seemingly anything involving the console.log() method will not display.
When I attempt to open the file in Chrome, I just get a blank page with no printout.
I have opened the file in the JavaScript console and no errors are reported (I get the
printout of the string “Hello” as expected). Previously I had an error which I resolved by adding !DOCTYPE inside the opening HTML tag.
I have Googled for answers and ensured that JavaScript is enabled in the Chrome privacy settings as directed. I’ve also looked on Stack Overflow, but haven’t found anything which allows me to solve the problem at such a basic level.
What am I missing here? Sorry if this seems like a very elementary question – I am new to this language.
I’m on Windows 11, running Chrome 131.0.6778.70 (the most recent version – I have updated as part of the troubleshooting process). Please let me know if any further information is needed.
Thanks in advance.
How to trigger inline script onload?
I have the following script, as seen, it calls the Date method onClick event, like so:
<!DOCTYPE html>
<html>
<body>
<p onclick='this.innerHTML = Date();'>click me!</p>
</body>
</html>
How can I do the same with an onLoad event? I don’t want to define it with a separate <script> tag and call it as a function. I’d like the most minimal coding.
Why doesn’t the following work?
<!DOCTYPE html>
<html>
<body>
<p onload='this.innerHTML = Date();'>date here onload</p>
</body>
</html>
