MediaWiki:Common.js: Difference between revisions

From Artifacts of Capitalism
No edit summary
No edit summary
Line 14: Line 14:
   $c.find('input[name="ns' + 3000 + '"]').closest('label, .mw-advancedSearch-ns_option').hide();
   $c.find('input[name="ns' + 3000 + '"]').closest('label, .mw-advancedSearch-ns_option').hide();
});
});
// Load Google CSE on the Advanced_search page and auto-run ?q=
(function () {
  var page = mw.config.get('wgPageName'); // spaces -> underscores
  if (
    page === 'Artifacts_of_Capitalism:Advanced_search' || // site name namespace alias
    page === 'Project:Advanced_search'                    // generic alias, just in case
  ) {
    // If you want the query in the box to auto-run from ?q=...
    window.__gcse = {
      searchCallbacks: {
        ready: function () {
          try {
            var params = new URLSearchParams(location.search);
            var q = params.get('q');
            if (!q) return;
            // CSE reads initial query from URL hash; set it then it runs.
            var hash = 'gsc.tab=0&gsc.q=' + encodeURIComponent(q);
            if (!location.hash || !location.hash.includes('gsc.q=')) {
              location.hash = hash;
            }
          } catch (e) {}
        }
      }
    };
    // Inject the Google CSE loader
    var s = document.createElement('script');
    s.async = true;
    s.src = 'https://cse.google.com/cse.js?cx=b194aa5e4d64344ad';
    document.body.appendChild(s);
  }
})();

Revision as of 17:07, 17 October 2025

// Ensure viewport meta exists (iOS layout fix)
(function () {
  if (!document.querySelector('meta[name="viewport"]')) {
    var m = document.createElement('meta');
    m.name = 'viewport';
    m.content = 'width=device-width, initial-scale=1, shrink-to-fit=no';
    document.head.appendChild(m);
  }
})();
mw.hook('wikipage.content').add(function ($c) {
  var groups = mw.config.get('wgUserGroups') || [];
  if (groups.indexOf('approver') !== -1) return; // approvers keep the checkbox
  // Hide the Draft namespace checkbox in the advanced search pane
  $c.find('input[name="ns' + 3000 + '"]').closest('label, .mw-advancedSearch-ns_option').hide();
});
// Load Google CSE on the Advanced_search page and auto-run ?q=
(function () {
  var page = mw.config.get('wgPageName'); // spaces -> underscores
  if (
    page === 'Artifacts_of_Capitalism:Advanced_search' || // site name namespace alias
    page === 'Project:Advanced_search'                    // generic alias, just in case
  ) {
    // If you want the query in the box to auto-run from ?q=...
    window.__gcse = {
      searchCallbacks: {
        ready: function () {
          try {
            var params = new URLSearchParams(location.search);
            var q = params.get('q');
            if (!q) return;
            // CSE reads initial query from URL hash; set it then it runs.
            var hash = 'gsc.tab=0&gsc.q=' + encodeURIComponent(q);
            if (!location.hash || !location.hash.includes('gsc.q=')) {
              location.hash = hash;
            }
          } catch (e) {}
        }
      }
    };

    // Inject the Google CSE loader
    var s = document.createElement('script');
    s.async = true;
    s.src = 'https://cse.google.com/cse.js?cx=b194aa5e4d64344ad';
    document.body.appendChild(s);
  }
})();