mgx

bulk canonical URL updater script for bear blog

![](https://static.mighil.com/images/2025/1762622766203_bear-blog-bulk-canonical-url-updater-script.webp) Sharing this script here for archive purposes and in case others find it useful when maintaining a self-hosted blog elsewhere. If you're in a similar situation -- running a custom domain that [programmatically mirrors](tab:https://mighil.com/status/unlinked-custom-domain-from-bear-blog) your Bear Blog or managing same posts across multiple platforms, this might save you some time. ### How to use it **Step 1: Install Tampermonkey** **Step 2: Add the Script** 1. Open Tampermonkey dashboard (click the Tampermonkey icon → Dashboard) 2. Click the **+** tab (or go to File → Create new script) 3. Delete the default template code 4. Copy and paste the [script from here](https://gist.github.com/verfasor/971416bb9fc8f04bc947530dc1ac08be). 5. **Important**: Update line 15 to use your domain: ```javascript const DOMAIN = 'https://yourdomain.com'; // Change this to your domain ``` 6. Save **Step 3: Run the script** ![](https://static.mighil.com/images/2025/1762623065644_bulk-update-canonical-urls-button.webp) 1. Login and navigate to your Bear Blog dashboard: `https://bearblog.dev/yourblog/dashboard/posts/` 2. You should see a green button in the top-right corner: **"Bulk Update Canonical URLs"** 3. Click the button 4. Confirm when prompted (it will show how many posts it found) 5. **Let it run** -- the script will automatically process all posts The script will automatically: - Open each post's edit page - Update the canonical URL - Save the post - Move to the next post - Continue until all posts are processed When it's done, you'll see an alert: "Finished processing X posts!" ### ⚠️ Important If you have couple hundreds or thousands of posts, be careful when running this script. Bear Blog's system may detect rapid automated requests as bot activity. To avoid this: 1. **Process in smaller batches**: Instead of processing all posts at once, consider running the script multiple times with smaller sets 2. **Increase delays**: If you have many posts, you can increase the timing delays in the script to make it slower and more human-like **Adjusting timing delays** If you need to slow down the script to avoid detection, you can adjust these delays in the script: - **Line 140**: `setTimeout(..., 800)` - Delay before processing each post (currently 800ms). Increase to 2000-3000ms for slower processing. - **Line 166**: `setTimeout(..., 500)` - Delay before moving to next post after save (currently 500ms). Increase to 1500-2000ms. - **Line 217**: `setTimeout(..., 1000)` - Fallback form submit delay (currently 1000ms). Increase to 2000-3000ms. If you're unsure, start with a small batch (10-20 posts) to test, then gradually increase if everything works smoothly.

Tagged in bear blog, tech