I tried creating a single bookmark with search word But I can’t get this to work. How can I bypass security to make it work ? Do I really have to enable debug mode ? Is it possible to switch debug mode without having to restart the browser (and discard all tabs)

Here is the code I tried

javascript:(async()=>{let t="S",n="GPT Classic",u="https://chatgpt.com/g/g-YyyyMT9XH-chatgpt-classic/?q=%25s",k="cc",g=(await PlacesUtils.bookmarks.search({parentGuid:PlacesUtils.bookmarks.toolbarGuid,title:t}))[0]?.guid||(await PlacesUtils.bookmarks.insert({parentGuid:PlacesUtils.bookmarks.toolbarGuid,title:t,type:PlacesUtils.bookmarks.TYPE_FOLDER})).guid;await PlacesUtils.bookmarks.insert({parentGuid:g,title:n,url:u}),await PlacesUtils.keywords.insert({keyword:k,url:u}),alert(`Bookmark "${n}" added to folder "${t}" with keyword "${k}"!`)})();

  • interdimensionalmemeOP
    link
    fedilink
    arrow-up
    2
    ·
    7 days ago

    Hello, I tried pasting that into the URL bar But firefox autoremoves the “javascript:” in front. When I type it manually still, it does nothing.

    So I pressed F12, went to console tab and pasted it there

    It fails with “Uncaught (in promise) ReferenceError: PlacesUtils is not defined”

    Here is a human readable version of this command

    I’m just trying to create a bookmark with a script, so I can create the 40 or so special bookmarks with search keywords that I want, without wiping all the bookmarks like an import would. Also I want to just automate this for my OS re-installation.

    javascript:(async () => {
        // Define variables for bookmark details
        let folderTitle = "S"; // The name of the folder where the bookmark will be stored
        let bookmarkTitle = "GPT Classic"; // The title of the bookmark
        let bookmarkURL = "https://chatgpt.com/g/g-YyyyMT9XH-chatgpt-classic/?q=%25s"; // URL of the bookmark, %25s is the URL-encoded version of %s
        let keyword = "cc"; // The keyword to access the bookmark directly from the address bar
    
        // Find or create the folder in the Bookmarks Toolbar
        let folderGuid = (await PlacesUtils.bookmarks.search({
            parentGuid: PlacesUtils.bookmarks.toolbarGuid, // Look in the Bookmarks Toolbar
            title: folderTitle // Look for the folder with the given title
        }))[0]?.guid; // If the folder is found, get its GUID
    
        if (!folderGuid) {
            // If the folder doesn't exist, create it
            folderGuid = (await PlacesUtils.bookmarks.insert({
                parentGuid: PlacesUtils.bookmarks.toolbarGuid, // Add it to the Bookmarks Toolbar
                title: folderTitle, // Use the specified folder title
                type: PlacesUtils.bookmarks.TYPE_FOLDER // Specify that it's a folder
            })).guid;
        }
    
        // Add the new bookmark to the folder
        await PlacesUtils.bookmarks.insert({
            parentGuid: folderGuid, // Add the bookmark inside the created folder
            title: bookmarkTitle, // Use the specified bookmark title
            url: bookmarkURL // Use the specified bookmark URL
        });
    
        // Add a keyword to the bookmark for quick access
        await PlacesUtils.keywords.insert({
            keyword: keyword, // The keyword that can be used in the address bar
            url: bookmarkURL // The URL associated with the keyword
        });
    
        // Notify the user that the bookmark and keyword were added successfully
        alert(`Bookmark "${bookmarkTitle}" added to folder "${folderTitle}" with keyword "${keyword}"!`);
    })();
    
    • MrOtherGuy@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      7 days ago

      F12 opens web developer tools - the console there runs scripts in the website context - you cannot use that to access browser internals like PlacesUtils.

      You need to run your script via browser console, I can’t remember a hotkey for it, but you can find it from menu > more tools… > browser console

      Also, I’m not sure but there’s a chance that browser console is “read-only” in release firefox - meaning you might not be able to run anything from it. If that is the case, then open normal web developer tools (F12) and go to its settings, there’s some checkbox there to enable “browser chrome debugging” or something like that. After checking that (and reopening browser console) you can run your function from browser console.