ということで
対象を一番上にヒットしたサイトに限定しURL中にキーワードを含む場合と含まない場合で分け、それを見てリダイレクトするようにしました。日本語ドメインや複数のキーワードが含まれる場合に対応できないのは仕様です
// ==UserScript== // @name yahoo_first_redirect // @namespace http://d.hatena.ne.jp/jigendaddy/ // @include https://search.yahoo.co.jp/search?* // @version 1 // @grant none // ==/UserScript== var result = document.evaluate('id("WS2m")/div[@class="w"][1]//span[@class="u"][./b]/text()', document, null, 7, null); var result2 = document.evaluate('id("WS2m")/div[@class="w"][1]//span[@class="u"]/b/text()', document, null, 7, null); var result3 = document.evaluate('id("WS2m")/div[@class="w"][1]//span[@class="u"][not(./b)]/text()', document, null, 7, null); //1番上にヒットしたサイトがURL中に検索したキーワードを含む場合 if(result.snapshotLength>0) { location.href="http://"+result.snapshotItem(0).data+result2.snapshotItem(0).data+result.snapshotItem(1).data; } //1番上にヒットしたサイトがURL中に検索したキーワードを含まない場合 else if(result3.snapshotLength>0) { location.href="http://"+result3.snapshotItem(0).data; }